#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  map<int, int> mp;
  int arr[n];
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    mp[x] = i;
    arr[i] = x;
  }
  vector<int> ans;
  map<int, int>::iterator it;
  for (int i = 0; i < m; i++) {
    int y;
    scanf("%d", &y);
    it = mp.find(y);
    if (it != mp.end()) {
      ans.push_back(mp[y]);
    }
  }
  sort(ans.begin(), ans.end());
  for (int i = 0; i < ans.size(); i++) {
    printf("%d ", arr[ans[i]]);
  }
  printf("\n");
  return 0;
}
