#include <bits/stdc++.h>
using namespace std;
vector<int> v(10);
vector<int> v2;
vector<int> rez;
int main() {
  int n, m, ans = -1, cur = 0, it;
  cin >> n >> m;
  v2.resize(m);
  for (int i = 0; i < n; i++) cin >> v[i];
  for (int i = 0; i < m; i++) cin >> v2[i];
  sort(v2.begin(), v2.end());
  do {
    cur = 0;
    it = 0;
    for (int i = 0; i < n; i++)
      if (v[i] == v2[it]) {
        cur++;
        it++;
        if (it == m) break;
      }
    if (cur > ans) {
      ans = cur;
      rez.clear();
      for (int i = 0; i < it; i++) rez.push_back(v2[i]);
    }
  } while (next_permutation(v2.begin(), v2.end()));
  for (int i = 0; i < rez.size(); i++) cout << rez[i] << " ";
  return 0;
}
