#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e6+7;
const int MAXN = maxn / 2;
int n,m,a[maxn],b[maxn];
//queue<int>q;
signed main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (a[i] == b[j])
cout << a[i] << ' ';
//cout << cnt;
return 0;
}