#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  long long int t, temp, i, ans = 0, n, m, index, j;
  cin >> n >> m;
  vector<pair<long long int, long long int> > pa;
  vector<long long int> v(n), finger(m);
  for (i = 0; i < n; i++) {
    cin >> v[i];
  }
  for (i = 0; i < m; i++) {
    cin >> finger[i];
    for (j = 0; j < n; j++) {
      if (v[j] == finger[i]) {
        pa.push_back(make_pair(j, finger[i]));
      }
    }
  }
  sort(pa.begin(), pa.end());
  if (pa.size() == 0)
    cout << '\n';
  else {
    for (auto it = pa.begin(); it != pa.end(); it++) {
      cout << it->second << " ";
    }
  }
}
