#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, b;
  set<int> st;
  cin >> n >> m;
  int a[n + 7];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < m; ++i) {
    cin >> b;
    st.insert(b);
  }
  for (int i = 0; i < n; ++i) {
    if (st.count(a[i])) cout << a[i] << " ";
  }
  puts("");
}
