#include <bits/stdc++.h>
using namespace std;
int x[1000];
int y[1000];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  int a, b;
  cin >> a >> b;
  for (int i = 1; i <= a; i++) {
    cin >> x[i];
  }
  for (int i = 1; i <= b; i++) {
    cin >> y[i];
  }
  for (int i = 1; i <= a; i++) {
    for (int j = 1; j <= b; j++) {
      if (x[i] == y[j]) cout << y[j] << " ";
    }
  }
  return 0;
}
