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