#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k = 0;
  cin >> n >> m;
  int arr[n], arr2[m], arr3[m];
  for (int i = 0; i < n; ++i) cin >> arr[i];
  for (int i = 0; i < m; ++i) {
    cin >> arr2[i];
    for (int j = 0; j < n; ++j)
      if (arr2[i] == arr[j]) {
        arr3[k++] = j;
        break;
      }
  }
  if (k == 0)
    cout << '\n';
  else {
    sort(arr3, arr3 + k);
    for (int i = 0; i < k; ++i) cout << arr[arr3[i]] << " ";
  }
  return 0;
}
