#include <bits/stdc++.h>
using namespace std;
void doRoutine() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
long long int n, m;
vector<long long int> x;
set<long long int> y;
signed main() {
  doRoutine();
  cin >> n >> m;
  x.resize(n);
  for (long long int i = 0; i < n; i++) cin >> x[i];
  for (long long int i = 0; i < m; i++) {
    long long int h;
    cin >> h;
    y.insert(h);
  }
  for (long long int i = 0; i < n; i++) {
    if (y.find(x[i]) != y.end()) cout << x[i] << " ";
  }
  return 0;
}
