#include <bits/stdc++.h>
using namespace std;
bool exist[30000];
bool ne_prost[100001];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int a[n], b[m];
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < m; i++) {
    scanf("%d", &b[i]);
    exist[b[i]]++;
  }
  for (int i = 0; i < n; i++) {
    if (exist[a[i]]) {
      cout << a[i] << " ";
    }
  }
  return 0;
}
