#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const double pi = 2 * acos(0.0);
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  long long seq[n];
  for (long long i = 0; i < n; i++) {
    cin >> seq[i];
  }
  long long print[m];
  for (long long i = 0; i < m; i++) {
    cin >> print[i];
  }
  sort(print, print + m);
  vector<long long> res;
  for (long long i = 0; i < n; i++) {
    if (binary_search(print, print + m, seq[i])) {
      res.push_back(seq[i]);
    }
  }
  for (auto el : res) {
    cout << el << " ";
  }
  cout << "\n";
  return 0;
}
