#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, n, m, i, j, num = 0, sum = 0;
  vector<int> vec, vec2, vec3;
  cin >> a >> b;
  while (a--) {
    cin >> n;
    vec.push_back(n);
  }
  while (b--) {
    cin >> m;
    vec2.push_back(m);
  }
  for (int i = 0; i < vec.size(); i++) {
    for (int j = 0; j < vec2.size(); j++) {
      if (vec[i] == vec2[j]) {
        vec3.push_back(vec[i]);
        break;
      }
    }
  }
  for (int i = 0; i < vec3.size(); i++) {
    if (i != vec3.size() - 1)
      cout << vec3[i] << " ";
    else
      cout << vec3[i] << endl;
  }
}
