#include <bits/stdc++.h>
using namespace std;
int n, m, x[1000000];
map<int, int> mp;
vector<int> ans;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> x[i];
  for (int i = 0; i < m; i++) {
    int t;
    cin >> t;
    mp[t]++;
  }
  for (int i = 0; i < n; i++) {
    if (mp[x[i]]) {
      mp[x[i]]--;
      ans.push_back(x[i]);
    }
  }
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i] << ((i != ans.size() - 1) ? " " : "");
  cout << endl;
  return 0;
}
