#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int m;
  cin >> n >> m;
  vector<int> v1;
  vector<int> v2;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v1.push_back(x);
  }
  set<int> s;
  for (int i = 0; i < m; i++) {
    int x;
    cin >> x;
    auto it = std::find(v1.begin(), v1.end(), x);
    if (it != v1.end()) {
      int val = it - v1.begin();
      s.insert(val);
    }
  }
  for (auto it = s.begin(); it != s.end(); it++) {
    cout << v1.at((*it)) << " ";
  }
  return 0;
}
