#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(n), v1(m);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  for (int i = 0; i < m; ++i) {
    cin >> v1[i];
  }
  vector<int> ans;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (v[i] == v1[j]) {
        ans.push_back(v[i]);
        break;
      }
    }
  }
  for (auto i : ans) {
    cout << i << " ";
  }
}
