#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int a[n + 1], b[m + 1];
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= m; i++) scanf("%d", &b[i]);
  set<int> dig;
  for (int i = 1; i <= m; i++) dig.insert(b[i]);
  for (int i = 1; i <= n; i++)
    if (dig.find(a[i]) != dig.end()) printf("%d ", a[i]);
  return 0;
}
