#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k, l;
  vector<int> seq;
  vector<int> pri;
  cin >> n;
  cin >> m;
  for (int i = 0; i <= n - 1; i++) {
    cin >> k;
    seq.push_back(k);
  }
  for (int i = 0; i <= m - 1; i++) {
    cin >> l;
    pri.push_back(l);
  }
  for (int i = 0; i <= seq.size() - 1; i++) {
    for (int j = 0; j <= pri.size() - 1; j++) {
      if (seq[i] == pri[j]) {
        cout << seq[i] << " ";
      }
    }
  }
}
