#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, x;
  cin >> n >> m;
  long long int ar[n];
  for (long long int i = 0; i < n; i++) cin >> ar[i];
  map<long long int, long long int> mp;
  for (long long int i = 0; i < m; i++) {
    cin >> x;
    mp[x] = 1;
  }
  for (long long int i = 0; i < n; i++) {
    if (mp[ar[i]] == 1) cout << ar[i] << " ";
  }
  return 0;
}
