#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  int n, m;
  cin >> n >> m;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  set<int> s;
  for (int i = 0; i < m; i++) {
    int temp;
    cin >> temp;
    s.insert(temp);
  }
  for (int i = 0; i < n; i++) {
    if (s.find(v[i]) != s.end()) {
      cout << v[i] << " ";
    }
  }
  cout << "\n";
  return 0;
}
