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