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