#include <bits/stdc++.h>
using namespace std;
const int mx = 200100;
const int md = 1000000007;
bool compare(const pair<int, int>& a, const pair<int, int>& b) {
  return a.first < b.first || (a.first == b.first && a.second > b.second);
}
int main() {
  int n, m;
  map<int, int> visit;
  vector<int> ans, arr;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i += 1) {
    int x;
    scanf("%d", &x);
    arr.push_back(x);
  }
  for (int i = 0; i < m; i += 1) {
    int x;
    scanf("%d", &x);
    visit[x] = 1;
  }
  for (int i = 0; i < n; i += 1) {
    if (visit[arr[i]]) ans.push_back(arr[i]);
  }
  for (int i = 0; i < ans.size(); i += 1) {
    printf("%d ", ans[i]);
  }
  printf("\n");
}
