#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
int main() {
  fast();
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  map<int, bool> chk;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < k; i++) {
    int x;
    cin >> x;
    chk[x] = 1;
  }
  int it = 0;
  while (it < k) {
    for (int j = 0; j < n; j++) {
      if (chk[a[j]]) {
        cout << a[j] << " ";
        chk[a[j]] = 0;
      }
    }
    it++;
  }
  return 0;
}
