#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a1[n], a2[m];
  for (int i = 0; i < n; ++i) cin >> a1[i];
  for (int i = 0; i < m; ++i) cin >> a2[i];
  vector<int> v;
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < n; ++j) {
      if (a2[i] == a1[j]) {
        v.push_back(j);
        break;
      }
    }
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); ++i) cout << a1[v[i]] << " ";
}
