#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int l = 1, h, i, n, x, t, q, y = -1, z = 0, a = 0, b = 0, c = 0, k,
                sum = 0, m, d = 0, r, w, j, ans, s, mini = INT_MAX,
                maxi = INT_MIN;
  bool cou;
  float kl;
  long long int count = 0;
  t = 1;
  vector<bool> sie(1000001, 0);
  char cg;
  string str, std;
  a = 1;
  while (t--) {
    cin >> n >> m;
    vector<int> vec(n);
    map<int, bool> mp;
    for (i = 0; i < n; ++i) cin >> vec[i];
    for (i = 0; i < m; ++i) {
      cin >> x;
      mp[x] = 1;
    }
    for (i = 0; i < n; ++i) {
      if (mp[vec[i]]) cout << vec[i] << " ";
    }
  }
}
