#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, num;
  vector<int> seq;
  vector<int> keys;
  set<int> answer;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> num;
    seq.push_back(num);
  }
  num = 0;
  for (int i = 0; i < m; ++i) {
    cin >> num;
    keys.push_back(num);
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (seq[i] == keys[j]) cout << seq[i] << " ";
    }
  }
  return 0;
}
