#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10;
const long long modd = 998244353;
long long inv[MAXN];
long long C[MAXN];
long long quick_mul(long long a, long long n) {
  a = (a % modd + modd) % modd;
  long long ans = 1;
  while (n) {
    if (n % 2) ans = ans * a % modd;
    n >>= 1;
    a = a * a % modd;
  }
  return ans;
}
void calC(long long n) {
  C[0] = 1;
  inv[1] = 1;
  for (int i = 1; i <= n; i++) {
    if (i > 1) inv[i] = (modd - modd / i) * inv[modd % i] % modd;
    C[i] = C[i - 1] * (n - i + 1) % modd * inv[i] % modd;
  }
}
int x[20], y[20];
int cnt[20];
vector<int> ans;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> x[i];
  for (int j = 1; j <= m; j++) cin >> y[j], cnt[y[j]]++;
  for (int i = 1; i <= n; i++)
    if (cnt[x[i]]) ans.push_back(x[i]);
  for (int i = 0; i < ans.size(); i++)
    if (i)
      cout << " " << ans[i];
    else
      cout << ans[i];
  cout << endl;
}
