#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const double eps = 1e-9;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
set<int> s;
int a[maxn];
int n, m, num;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < (m); ++i) {
    scanf("%d", &num);
    s.insert(num);
  }
  for (int i = 0; i < (n); ++i) {
    if (s.count(a[i])) printf("%d ", a[i]);
  }
  puts("");
  return 0;
}
