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