#include <bits/stdc++.h>
using namespace std;
int m, n;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n], b[m];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int temp[10] = {0};
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    temp[b[i]] = 1;
  }
  for (int i = 0; i < n; i++) {
    if (temp[a[i]] == 1) {
      cout << a[i] << " ";
    }
  }
  return 0;
}
