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