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