#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a;
  cin >> n >> m;
  int arr[n], l[10] = {0};
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int i = 0; i < m; i++) {
    cin >> a;
    l[a] = 1;
  }
  for (int i = 0; i < n; i++) {
    if (l[arr[i]]) cout << arr[i] << " ";
  }
  cout << endl;
}
