#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int seq[n];
  int fingerprint[m];
  unordered_map<int, int> map;
  for (int i = 0; i < n; i++) {
    cin >> seq[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> fingerprint[i];
    map[fingerprint[i]] = 1;
  }
  for (int i = 0; i < n; i++) {
    if (map[seq[i]] >= 1) {
      cout << seq[i] << " ";
    }
  }
  cout << endl;
}
