#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > cnt;
int ord[100];
set<int> s;
int n, m;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    ord[x] = i;
    s.insert(x);
  }
  for (int i = 0; i < m; i++) {
    int x;
    cin >> x;
    if (s.find(x) != s.end()) cnt.push_back(pair<int, int>(ord[x], x));
  }
  sort(cnt.begin(), cnt.end());
  for (auto x : cnt) cout << x.second << " ";
}
