#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, k;
  cin >> n >> k;
  long long a[n], b[k];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<pair<long long, long long> > v;
  for (long long i = 0; i < k; i++) {
    long long c;
    cin >> c;
    for (long long i = 0; i < n; i++) {
      if (a[i] == c) v.push_back({i, c});
    }
  }
  sort(v.begin(), v.end());
  for (auto it : v) cout << it.second << ' ';
  return 0;
}
