#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  pair<int, bool> a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = false;
  }
  for (int i = 0; i < m; i++) {
    int x;
    cin >> x;
    for (int j = 0; j < n; j++) {
      if (a[j].first == x) a[j].second = true;
    }
  }
  for (int j = 0; j < n; j++) {
    if (a[j].second) cout << a[j].first << " ";
  }
  cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
}
