#include
#include
#include
#include
int main() {
int n, m;
scanf("%d%d", &n, &m);
int matrica[n][m];
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
scanf("%d", &matrica[i][j]);
}
}
int x;
while(scanf("%d", &x)) {
for(int i = 0; i < n; i++) {
int dali_e_prisuten_brojot = 0;
for(int j = 0; j < m; j++) {
if(matrica[i][j] == x) {
dali_e_prisuten_brojot = 1;
break;
}
}
if(dali_e_prisuten_brojot == 1) {
for(int j = 0; j < m; j++) {
matrica[i][j] = -1;
}
}
}
}
for(int i = 0; i < n; i++) {
if(matrica[i][0] == -1) {
continue;
}
for(int j = 0; j < m; j++) {
printf("%d ", matrica[i][j]);
}
printf("\n");
}
return 0;
}
/*
4 4
1 0 2 4
3 3 23 5
3 5 5 6
0 3 12 7
**/