#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<int> seq(n);
  for (int i = 0; i < n; i++) cin >> seq[i];
  set<int> prints;
  for (int j = 0; j < m; j++) {
    int key;
    cin >> key;
    prints.insert(key);
  }
  for (int i : seq) {
    if (prints.count(i)) cout << i << " ";
  }
  cout << endl;
  return 0;
}
