#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(m), ans;
  for (int i = 0; i < n; ++i) cin >> a[i];
  set<int> s;
  for (int i = 0; i < m; ++i) {
    cin >> b[i];
    s.insert(b[i]);
  }
  for (int i = 0; i < n; ++i) {
    if (s.count(a[i])) ans.push_back(a[i]);
  }
  for (int i = 0; i < ans.size(); ++i) cout << ans[i] << " ";
}
