#include <bits/stdc++.h>
using namespace std;
long long int n, x, ans, m;
long long int a[2005];
long long int b[2005];
string str;
long long int solve() { return 0; }
long long int input() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < m; ++i) {
    cin >> b[i];
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (a[i] == b[j]) {
        cout << a[i] << " ";
        break;
      }
    }
  }
  cout << endl;
  return 0;
}
int main() {
  input();
  solve();
  return 0;
}
