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