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