#include <bits/stdc++.h>
int main() {
  int m, n;
  scanf("%d %d", &n, &m);
  int *squence = (int *)calloc(n, (sizeof(int)));
  int *fingerprint = (int *)calloc(m, (sizeof(int)));
  int j, h;
  j = 0;
  h = 0;
  for (j = 0; j < n; j++) {
    scanf("%d", &squence[j]);
  }
  j = 0;
  for (j = 0; j < m; j++) {
    scanf("%d", &fingerprint[j]);
  }
  j = 0;
  for (j = 0; j < n; j++) {
    for (h = 0; h < m; h++) {
      if (squence[j] == fingerprint[h]) {
        printf("%d ", squence[j]);
        break;
      }
    }
  }
  return 0;
}
