#include <bits/stdc++.h>
using namespace std;
long long fexp(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % 998244353;
    b /= 2;
    a = a * a % 998244353;
  }
  return ans;
}
long long inverse(long long a, long long p) { return fexp(a, p - 2); }
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long m, n;
  cin >> m >> n;
  vector<long long> v;
  vector<long long> v1;
  for (long long i = 0; i < m; i++) {
    long long a;
    cin >> a;
    v.push_back(a);
  }
  for (long long i = 0; i < n; i++) {
    long long a;
    cin >> a;
    v1.push_back(a);
  }
  long long f = 0;
  for (long long i = 0; i < m; i++) {
    if (f == n) {
      break;
    }
    if (find((v1).begin(), (v1).end(), v[i]) != v1.end()) {
      cout << v[i] << " ";
      f++;
    }
  }
  return 0;
}
