#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> A(n);
  vector<bool> C(n, false);
  for (int i = 0; i < n; ++i) cin >> A[i];
  for (int i = 0; i < m; ++i) {
    int b;
    cin >> b;
    for (int j = 0; j < n; ++j)
      if (A[j] == b) C[j] = true;
  }
  vector<int> ans, tmp;
  for (int i = 0; i < n; ++i) {
    if (C[i]) {
      ans.push_back(A[i]);
    }
  }
  for (int i = 0; i < ans.size(); ++i) cout << ans[i] << " ";
}
