#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, r, c = 0;
  cin >> n >> m;
  set<long long> s1;
  long long a[n];
  set<long long>::iterator it;
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < m; i++) {
    cin >> r;
    s1.insert(r);
  }
  vector<long long> v;
  for (long long i = 0; i < n; i++) {
    it = s1.find(a[i]);
    if (it != s1.end()) {
      v.push_back(a[i]);
    }
  }
  for (long long i = 0; i < v.size(); i++) cout << v[i] << " ";
  cout << endl;
  return 0;
}
