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