#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, c = 0, nmb = 0;
  cin >> n >> m;
  int *izvest = new int[n];
  int *otpech = new int[m];
  for (int i = 0; i < n; i++) {
    cin >> izvest[i];
  }
  for (int j = 0; j < m; j++) {
    cin >> otpech[j];
  }
  for (int cnt1 = 0; cnt1 < n; cnt1++) {
    for (int cnt2 = 0; cnt2 < m; cnt2++) {
      if (izvest[cnt1] == otpech[cnt2]) {
        c++;
      }
    }
  }
  int *zapis = new int[c];
  for (int cnt2_1 = 0; cnt2_1 < n; cnt2_1++) {
    for (int cnt2_2 = 0; cnt2_2 < m; cnt2_2++) {
      if (izvest[cnt2_1] == otpech[cnt2_2]) {
        zapis[nmb] = izvest[cnt2_1];
        nmb++;
      }
    }
  }
  for (int y = 0; y < c; y++) {
    cout << zapis[y] << ' ';
  }
  return 0;
}
