#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,m,a[100001],b[100001];
cin >> n >> m;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
}
for(int i = 1; i <= m; i++)
{
cin >> b[i];
}
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
if(a[i] == b[j])
{
cout << a[i] << " ";
}
}
}
return 0;
}