#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  int arr[n], arr1[m];
  map<int, bool> mp;
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int i = 0; i <= m - 1; i++) {
    cin >> arr1[i];
    mp[arr1[i]] = true;
  }
  for (int i = 0; i <= n - 1; i++) {
    if (mp[arr[i]] == true) cout << arr[i] << " ";
  }
  return 0;
}
