#include <bits/stdc++.h>
using namespace std;
inline void fast() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
int main() {
  fast();
  int n, m;
  cin >> n >> m;
  int a[n], b[m];
  int vis[10] = {0};
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    vis[b[i]]++;
  }
  for (int i = 0; i < n; i++) {
    if (vis[a[i]]) {
      cout << a[i] << " ";
    }
  }
  cout << endl;
  return 0;
}
