#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, m, n, a1[10], a2[10], pos[10];
  cin >> n >> m;
  for (i = 0; i < n; i++) cin >> a1[i];
  for (j = 0; j < m; j++) cin >> a2[j];
  int count;
  for (i = 0; i < m; i++) {
    count = 0;
    for (j = 0; j < n; j++) {
      if (a1[j] == a2[i]) {
        count = 1;
        pos[i] = j;
        break;
      }
    }
    if (count == 0) a2[i] = -1;
  }
  int temp;
  for (i = 0; i < m - 1; i++)
    for (j = 0; j < m - i - 1; j++) {
      if (pos[j] > pos[j + 1]) {
        temp = a2[j];
        a2[j] = a2[j + 1];
        a2[j + 1] = temp;
        temp = pos[j];
        pos[j] = pos[j + 1];
        pos[j + 1] = temp;
      }
    }
  for (i = 0; i < m; i++)
    if (a2[i] >= 0) cout << a2[i] << " ";
  return 0;
}
