#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, n, m;
  cin >> n >> m;
  int a[n], b[m], c[max(n, m)];
  bool ans[n];
  int k = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    ans[i] = false;
  }
  for (i = 0; i < m; i++) {
    cin >> b[i];
    for (j = 0; j < n; j++) {
      if (b[i] == a[j]) {
        ans[j] = true;
      }
    }
  }
  for (i = 0; i < n; i++) {
    if (ans[i] == true) cout << a[i] << " ";
  }
  cout << endl;
}
