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