#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n], b[m];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) cin >> b[i];
  int c[n];
  for (int i = 0; i < n; i++) {
    int check = a[i];
    int j = 0;
    for (; j < m; j++)
      if (b[j] == check) {
        c[i] = 1;
        break;
      }
    if (j == m) c[i] = 0;
  }
  for (int i = 0; i < n; i++)
    if (c[i] == 1) cout << a[i] << " ";
  return 0;
}
