#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int seq[n], fp[m], arr[m], p = 0;
  for (int i = 0; i < n; i++) {
    cin >> seq[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> fp[i];
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (fp[i] == seq[j]) {
        arr[p] = j;
        p++;
      }
    }
  }
  sort(arr, arr + p);
  for (int i = 0; i < p; i++) {
    cout << seq[arr[i]] << " ";
  }
  return 0;
}
