#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, mn;
  cin >> n >> mn;
  map<long long, long long> m;
  vector<pair<long long, long long> > v;
  long long a;
  for (long long i = (long long)0; i < (long long)n; i++) {
    cin >> a;
    m[a] = i;
  }
  for (long long i = (long long)0; i < (long long)mn; i++) {
    cin >> a;
    if (m.find(a) != m.end()) {
      v.push_back(make_pair(m[a], a));
    }
  }
  sort(v.begin(), v.end());
  for (long long i = (long long)0; i < (long long)v.size(); i++) {
    pair<long long, long long> p = v[i];
    cout << p.second << " ";
  }
  return 0;
}
