#include <bits/stdc++.h>
using namespace std;
void insertionSort(int arr[], int n) {
  int i, key, j;
  for (i = 1; i < n; i++) {
    key = arr[i];
    j = i - 1;
    while (j >= 0 && arr[j] > key) {
      arr[j + 1] = arr[j];
      j = j - 1;
    }
    arr[j + 1] = key;
  }
}
int main() {
  int n, m, i, j, coun = 0;
  cin >> n >> m;
  int arr[10], arr1[10];
  int arr2[10];
  for (i = 0; i < n; i++) cin >> arr[i];
  for (i = 0; i < m; i++) cin >> arr1[i];
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      if (arr1[i] == arr[j]) {
        arr2[coun] = j;
        coun++;
      }
    }
  }
  insertionSort(arr2, coun);
  for (i = 0; i < coun; i++) cout << arr[arr2[i]] << " ";
  return 0;
}
