#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, c, d, j;
  vector<pair<int, int> > v;
  cin >> n >> m;
  int a[11], b[11];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < m; i++) {
    cin >> c;
    for (j = 0; j < n; j++) {
      if (a[j] == c) {
        v.push_back(make_pair(j, c));
        break;
      }
    }
  }
  sort(v.begin(), v.end());
  for (i = 0; i < v.size(); i++) cout << v[i].second << " ";
  cout << endl;
}
