You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.

Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code.


-----Input-----

The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints.

The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequence.

The next line contains $m$ distinct space-separated integers $y_1, y_2, \ldots, y_m$ ($0 \le y_i \le 9$) — the keys with fingerprints.


-----Output-----

In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable.


-----Examples-----
Input
7 3
3 5 7 1 6 2 8
1 2 7

Output
7 1 2

Input
4 4
3 4 1 0
0 1 7 9

Output
1 0



-----Note-----

In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.

In the second example digits $0$, $1$, $7$ and $9$ have fingerprints, however only $0$ and $1$ appear in the original sequence. $1$ appears earlier, so the output is 1 0. Again, the order is important.

Source: codeforces | Difficulty: EASY
Tags: Implementation


Solutions:
(n, m) = input().split()
n = int(n)
m = int(m)
a = list(map(int, input().split()))[:n]
b = list(map(int, input().split()))[:m]
c = []
d = {}
for i in range(m):
	if a.__contains__(b[i]):
		c.append(a.index(b[i]))
		d.setdefault(a.index(b[i]), b[i])
c.sort()
for i in range(len(c)):
	print(d.get(c[i]), end=' ')


(n, m) = map(int, input().split())
a = [int(n) for n in input().split()]
b = [int(n) for n in input().split()]
for i in range(n):
	for j in range(m):
		if a[i] == b[j]:
			print(a[i], end=' ')


(a, b, c) = (input().split(), input().split(), input().split())
print(*[d for d in b if d in c])


(n, m) = list(map(int, input().split()))
k1 = input().split()
k2 = input().split()
for i in k1:
	if i in k2:
		print(i, end=' ')


(x, y) = input('').split()
lst1 = list(map(int, input().split()))
lst2 = list(map(int, input().split()))
for n in lst1:
	if n in lst2:
		print(n, end=' ')


(n, m) = [int(x) for x in input().split()]
seq = [int(x) for x in input().split()]
fig = [int(x) for x in input().split()]
code = []
for i in seq:
	if i in fig:
		code.append(i)
if len(code) > 0:
	print(*code)
else:
	print()


line1 = list(input().split())
line2 = list(input().split())
line3 = list(input().split())
for i in line2:
	for j in line3:
		if i == j:
			print(i, end=' ')
			break


(n, m) = input().split()
(n, m) = [int(n), int(m)]
l1 = [int(x) for x in input().split()]
l2 = [int(x) for x in input().split()]
x = len(l1)
x2 = len(l2)
l3 = []
for i in range(x):
	for j in range(x2):
		if l1[i] == l2[j]:
			l3.append(l1[i])
print(*l3, sep=' ')


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for x in a:
	if x in b:
		c.append(x)
print(*c)


(n, m) = map(int, input().split())
n_list = list(map(int, input().split()))
m_list = list(map(int, input().split()))
ans = ''
for item in n_list:
	if item in m_list:
		ans += str(item) + ' '
print(ans)


nm = list(map(int, input().split()))
a = list(map(int, input().split()))
x = list(map(int, input().split()))
b = set(x)
x = list(b)
res = []
for k in range(nm[0]):
	if x.count(a[k]) != 0:
		res.append(a[k])
for k in range(len(res)):
	print(res[k], end=' ')
print()


inp = input().split()
n = inp[0]
m = inp[1]
sequence = input().split()
keys = input().split()
indeces = []
for i in range(len(keys)):
	for j in range(len(sequence)):
		if keys[i] == sequence[j]:
			indeces.append(j)
if len(indeces) != 0:
	indeces.sort()
a = ''
for i in indeces:
	a = a + str(sequence[i]) + ' '
print(a)


(n, m) = input().split()
n = int(n)
m = int(m)
vals = [int(i) for i in input().split()]
fingerprinted = [int(i) for i in input().split()]
ans = []
for val in vals:
	if val in fingerprinted:
		ans.append(val)
if ans == []:
	print()
else:
	for i in ans:
		print(i, end=' ')
	print()


rd = lambda : list(map(int, input().split()))
input()
(a, b) = (rd(), rd())
print(*[x for x in a if x in b])


(n, m) = map(int, input().split())
s = list(map(int, input().split()))
f = list(map(int, input().split()))
for i in range(n):
	if s[i] in f:
		print(s[i], end=' ')


(m, n) = [int(i) for i in input().split()]
cons = input().split()
real = [i for i in input().split()]
ht = {}
for i in real:
	ht[i] = True
ans = []
for i in cons:
	if ht.get(i, None) == True:
		ans.append(i)
print(' '.join(ans))


(n, m) = map(int, input().split())
seq = list(map(str, input().split()))
fp = list(map(str, input().split()))
checklist = []
for number in seq:
	if number in fp:
		checklist.append(number)
print(' '.join(checklist))


IL = lambda : list(map(int, input().split()))
(n, m) = IL()
X = IL()
Y = IL()
print(*[x for x in X if x in Y])


(n, m) = input().split()
(n, m) = (int(n), int(m))
seq = input().split()
keys = input().split()
out = []
for i in seq:
	if i in keys:
		out.append(i)
print(' '.join(out))


(n, m) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
ans = ''
for i in a:
	if i in b:
		ans += str(i) + ' '
print(ans)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = ''
for i in range(n):
	if a[i] in b:
		s += str(a[i]) + ' '
print(s)


(a, b) = map(int, input().split())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
m = []
for i in l1:
	if i in l2:
		m.append(i)
if m == []:
	print(' ')
else:
	for j in m:
		print(j, end=' ')


a = input().split()
b = input().split()
c = input().split()
ans = []
for i in b:
	if i in c:
		ans.append(i)
print(' '.join(ans))


(n, m) = list(map(int, input().strip().split(' ')))
seq = list(map(int, input().strip().split(' ')))
f = list(map(int, input().strip().split(' ')))
ans = []
for s in seq:
	if s in f:
		ans.append(s)
print(*ans, sep=' ')


q = input()
(n, m) = q.split()
n = int(n)
m = int(m)
n11 = input().split()
m11 = input().split()
for i1 in range(n):
	if n11[i1] in m11:
		print(n11[i1], end=' ')


(n, m) = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
l = []
for i in range(0, m):
	try:
		p = x.index(y[i])
		l.append(p)
		i += 1
	except ValueError:
		i += 1
l.sort()
for i in l:
	print(x[i], end=' ')


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
r = list(map(int, input().split()))
for i in range(n):
	for j in range(k):
		if l[i] == r[j]:
			print(l[i], end=' ')


a = input().split()
b = input().split()
c = input().split()
d = []
for e in range(int(a[0])):
	if b[e] in c:
		d.append(b[e])
print(' '.join(d))


n_m = input()
n_m = [int(i) for i in n_m.split(' ')]
seq = input()
seq = [int(i) for i in seq.split(' ')]
fingers = input()
fingers = [int(i) for i in fingers.split(' ')]
answer = ''
for i in seq:
	if i in fingers:
		if answer == '':
			answer += str(i)
		else:
			answer += ' ' + str(i)
print(answer)


l = list(map(int, input().split()))
m = list(map(int, input().split()))
n = list(map(int, input().split()))
o = []
for i in m:
	if i in n:
		o.append(i)
for i in o:
	print(i, end=' ')


input()
(x, y) = (input().split(), set(input().split()))
print(' '.join([c for c in x if c in y]))


(n, m) = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
res = [x for x in a if x in b]
print(*res)


import re
import math
import decimal
import bisect

def read():
	return input().strip()

def iread():
	return int(input().strip())

def viread():
	return [int(x) for x in input().strip().split()]
read()
lst = viread()
ok = set(viread())
toprint = []
for i in lst:
	if i in ok:
		toprint.append(i)
print(*toprint)


input()
x = [int(k) for k in input().split()]
y = [int(k) for k in input().split()]
i = 0
s = len(x)
while i < s:
	if x[i] not in y:
		x.pop(i)
	else:
		i += 1
	s = len(x)
print(*x)


try:
	(n, m) = map(int, input().split())
	sequence = list(map(int, input().split()))
	fingerprint = list(map(int, input().split()))
	for each in range(0, n):
		if sequence[each] in fingerprint:
			print(sequence[each], end=' ')
except:
	pass


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(*[i for i in a if i in b])


m_n = input()
m_n = m_n.split(' ')
m_n = [int(i) for i in m_n]
(m, n) = (m_n[0], m_n[1])
sequence = input()
sequence = sequence.split(' ')
sequence = [int(i) for i in sequence]
keys_fingerprints = input()
keys_fingerprints = keys_fingerprints.split(' ')
keys_fingerprints = [int(i) for i in keys_fingerprints]
password_list = []
for seq in sequence:
	if seq in keys_fingerprints:
		password_list.append(seq)
password = ''
for p in password_list:
	password += str(p)
	password += ' '
password = password[:-1]
print(password)


(n, m) = map(int, input().split())
x = 2
l = list(map(int, input().split()))
m = list(map(int, input().split()))
for fp in l:
	if fp in m:
		print(fp, end=' ')


(n, m) = map(int, input().split())
known = list(map(int, input().split()))
marks = set(map(int, input().split()))
answer = []
for num in known:
	if num in marks:
		answer.append(num)
print(*answer)


import sys
x = input()
n = list(map(int, x.split()))
x = input()
l1 = list(map(int, x.split()))
x = input()
l2 = list(map(int, x.split()))
l = []
for i in l2:
	if i in l1:
		l.append(i)
for i in l1:
	if i in l:
		print(i, end=' ')


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l1 = list(map(int, input().split()))
l3 = []
for i in range(len(l)):
	if l[i] in l1:
		l3.append(l[i])
for i in range(len(l1)):
	if l1[i] in l and l1[i] not in l3:
		l3.append(l1[i])
if len(l3) == 0:
	print('')
else:
	for i in range(len(l3)):
		print(l3[i], end=' ')


(n, m) = map(int, input().split())
x = [int(i) for i in input().split()]
y = [int(j) for j in input().split()]
z = []
for k in range(0, n):
	for l in range(m):
		if x[k] == y[l]:
			z.append(x[k])
			break
print(' '.join(map(str, z)))


a = [int(q) for q in input().strip().split()]
b = [int(q) for q in input().strip().split()]
c = [int(q) for q in input().strip().split()]
d = []
for k in range(len(b)):
	if b[k] in c:
		d.append(str(b[k]))
print(' '.join(d))


(n, m) = map(int, input().split())
x = [int(q) for q in input().split()]
y = [int(w) for w in input().split()]
p = []
for i in y:
	if i in x:
		p.append(i)
u = []
for i in range(len(x)):
	if x[i] in p:
		u.append(x[i])
print(*u)


def str_to_int(str_list):
	return [int(x) for x in str_list]
dimensions = str_to_int(input().split(' '))
sequence = str_to_int(input().split(' '))
fingerprints = str_to_int(input().split(' '))
result = ''
for number in sequence:
	if number in fingerprints:
		result += '%d ' % number
print(result)


q = lambda : map(int, input().split())
qi = lambda : int(input())
qs = lambda : input().split()
(n, m) = q()
a = list(q())
b = list(q())
print(*[i for i in a if i in b])


(number1, number2) = input().split()
lst1 = list(map(int, input().split()))
lst2 = list(map(int, input().split()))
for x in lst1:
	for y in lst2:
		if x == y:
			print(y, end=' ')


(n, m) = map(int, input().split())
x = list(map(int, input().split()))
y = set(map(int, input().split()))
print(' '.join((str(el) for el in x if el in y)))


input()
x = [int(k) for k in input().split()]
y = [int(k) for k in input().split()]
for n in x:
	if n in y:
		print(n, end=' ')


(n, m) = map(int, input().split())
x = input().split()
y = input().split()
for i in range(n):
	if x[i] in y:
		y.remove(x[i])
		print(x[i], end=' ')


(n, m) = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
t = [False for _ in range(n)]
for yy in y:
	for i in range(n):
		if yy == x[i]:
			t[i] = True
else:
	ans = []
	for i in range(n):
		if t[i]:
			ans.append(x[i])
print(*ans)


import collections
from functools import cmp_to_key
import sys

def getIntList():
	return list(map(int, input().split()))
import bisect
(n, m) = getIntList()
x = getIntList()
y = getIntList()
y = set(y)
for x0 in x:
	if x0 in y:
		print(x0, end=' ')


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
fing = list(map(int, input().split()))
res = []
for i in arr:
	if i in fing:
		res.append(i)
print(*res)


(n, m) = map(int, input().split())
a = input().split()
b = input().split()
c = []
for i in b:
	if i in a:
		c.append(a.index(i))
c = sorted(c)
for i in c:
	print(a[i], end=' ')


(a, b) = input().split()
a = int(a)
b = int(b)
seq = list(map(int, input().split()))
f_p = list(map(int, input().split()))
ans = ''
for i in seq:
	if i in f_p:
		ans = ans + str(i)
		ans = str(ans) + ' '
print(ans)


(dum, seq, fp) = (input(), list(map(int, input().split())), list(map(int, input().split())))
print(' '.join((str(x) for x in seq if x in fp)))


n = list(map(int, input().split()))
l = list(map(int, input().split()))
f = list(map(int, input().split()))
c = []
for i in range(0, len(l)):
	if l[i] in f:
		c.append(l[i])
print(*c)


(n, m) = map(int, input().split())
xs = map(int, input().split())
ys = map(int, input().split())
flags = [False] * 10
for y in ys:
	flags[y] = True
res = (str(x) for x in xs if flags[x])
print(' '.join(res))


(n, m) = map(int, input().split())
mass1 = list(map(int, input().split()))
mass2 = list(map(int, input().split()))
for i in range(n):
	if mass1[i] in mass2:
		print(mass1[i], end=' ')


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * 10
for i in list(map(int, input().split())):
	b[i] = 1
for i in a:
	if b[i] == 1:
		print(i, end=' ')


(n, m) = input().split()
n = int(n)
m = int(m)
x = [int(x) for x in input().split()]
y = [int(x) for x in input().split()]
l = []
for i in x:
	if i in y:
		print(i, end=' ')


x = input()
seq = input().replace(' ', '')
f = input()
for e in seq:
	if e in f:
		print(e, end=' ')


(n, m) = map(int, input().split())
listN = list(map(int, input().split()))
listM = list(map(int, input().split()))
list = []
for i in range(0, n):
	for a in range(0, m):
		if listN[i] == listM[a]:
			list.append(listN[i])
code = ' '.join(map(str, list))
print(code)


n = list(map(int, input().split()))
code = list(map(int, input().split()))
fprints = list(map(int, input().split()))
fpos = []
fprints.sort()

def solve(n, code, fprints):
	for fprint in fprints:
		if fprint in code:
			fpos.append(code.index(fprint))
	fpos.sort()
	for x in fpos:
		print(code[x], end=' ')
solve(n, code, fprints)


(n, m) = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
r = ''
for i in x:
	if i in y:
		r += str(i) + ' '
print(r)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
x = list(map(int, input().split()))
for i in l:
	if i in x:
		print(i, end=' ')


(n, m) = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
f = [0] * n
for i in y:
	for j in range(n):
		if x[j] == i:
			f[j] = 1
for i in range(n):
	if f[i] == 1:
		print(x[i], end=' ')


(a, b) = map(int, input().split())
c = list(map(int, input().split()))
d = list(map(int, input().split()))
for i in c:
	if i in d:
		print(i, end=' ')


(n, m) = map(int, input().split())
ar1 = list(map(int, input().split()))
ar2 = list(map(int, input().split()))
for i in ar1:
	if i in ar2:
		print(i, end=' ')


(n, m) = map(int, input().split())
a = [int(s) for s in input().split()]
b = [int(x) for x in input().split()]
for i in a:
	if i in b:
		print(i)


(n, m) = map(int, input().split())
ln = list(input().split())
lm = list(input().split())
ans = ''
d = {}
for i in lm:
	d[i] = 1
for i in ln:
	if i in d:
		ans = ans + i + ' '
print(ans)


(n, m) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
i = 0
j = 0
ans = ''
for i in a:
	if i in b:
		ans += str(i) + ' '
print(ans)


(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
ans = []
for i in range(n):
	if a[i] in b:
		ans.append(a[i])
for i in ans:
	print(i, end=' ')


TN = 1

def solution():
	(n, m) = map(int, input().split())
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	l = []
	for i in range(n):
		for j in range(m):
			if x[i] == y[j]:
				l.append(str(x[i]))
	print(' '.join(l))
while TN != 0:
	solution()
	TN -= 1


(n, k) = [int(x) for x in input().split()]
lst1 = [int(x) for x in input().split()]
lst2 = [int(x) for x in input().split()]
lst3 = {}
ans = []
for i in lst2:
	if i in lst1:
		lst3[i] = lst1.index(i)
for i in sorted(lst3, key=lst3.get):
	ans.append(i)
print(*ans, sep=' ')


(n, m) = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
z = []
for i in x:
	if i in y:
		z.append(i)
print(' '.join(map(str, z)))


input()
x = list(map(int, input().split()))
y = list(map(int, input().split()))
print(*sorted(set(x) & set(y), key=lambda a: x.index(a)))


(n, m) = map(int, input().split())
seq = list(map(int, input().split()))
fprint = list(map(int, input().split()))
common = set(seq).intersection(set(fprint))
index = []
for i in common:
	index.append(seq.index(i))
index = sorted(index)
for i in index:
	print(seq[i], end=' ')


(n, k) = map(int, input().split())
li = list(map(int, input().split()))
s = sorted(list(map(int, input().split())), reverse=True)
a = []
for i in li:
	if i in s:
		a.append(i)
print(*a)


(n, m) = map(int, input().split())
ans = list(map(int, input().split()))
st = set(map(int, input().split()))
for i in ans:
	if i in st:
		print(i, end=' ')


(a, b) = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
arr1 = [int(x) for x in input().split()]
for i in arr:
	if i in arr1:
		print(i, end=' ')


a = [int(i) for i in input().split()]
(n, m) = (a[0], a[1])
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
array = []
for i in range(n):
	for j in range(m):
		if x[i] == y[j]:
			array += [x[i]]
for i in array:
	print(i, end=' ')


(n, m) = map(int, input().split())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
d2 = {}
for i in l2:
	if i in d2:
		d2[i] += 1
	else:
		d2[i] = 1
for i in l1:
	if i in d2:
		print(i, end=' ')
		d2[i] -= 1
		if d2[i] <= 0:
			del d2[i]


num1 = input()
num2 = [int(i) for i in input().split()]
num3 = [int(i) for i in input().split()]
seq = ''
for i in range(0, len(num2)):
	for num in num3:
		if num == num2[i]:
			seq += str(num) + ' '
print(seq)


(n, m) = list(map(int, input().split()))
list1 = list(map(int, input().split()))
list2 = list(map(int, input().split()))
for i in list1:
	if i in list2:
		print(i, end=' ')


(n, m) = map(int, input().split(' '))
sequence = list(map(int, input().split(' ')))
fingerprints = list(map(int, input().split(' ')))
for key in sequence:
	if key in fingerprints:
		print(key, end=' ')


def main():
	(n, m) = map(int, input().split())
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	index = []
	for yv in y:
		for (i, xv) in enumerate(x):
			if yv == xv:
				index.append(i)
	index.sort()
	for i in index:
		print(x[i], end=' ')
	print()
main()


import sys, math
debug = 0
if debug:
	f = open('input.txt', 'r')
	input = f.readline

def main():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = []
	for i in a:
		if i in b:
			ans.append(i)
	print(*ans)
	return
main()


(n, m) = map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
print(*sorted([x for x in arr2 if x in arr1], key=lambda k: arr1.index(k)))


def inline():
	return [int(e) for e in input().split()]

def inset():
	return set(inline())
inline()
code = inline()
prints = inset()
for e in code:
	if e in prints:
		print(e, end=' ')
print()


(n, m) = map(int, input().split())
x = list(map(int, input().split()))
y = [int(i) for i in input().split()]
result = []
for i in x:
	if i in y:
		result.append(i)
print(*result)


(n, m) = map(int, input().split())
xs = map(int, input().split())
ns = set(map(int, input().split()))
print(' '.join((str(x) for x in xs if x in ns)))


(n, m) = map(int, input().split())
a = [int(i) for i in input().split()]
ans = []
b = [int(i) for i in input().split()]
s = [0 for i in range(11)]
for i in b:
	s[i] = 1
for i in a:
	if s[i] == 1:
		ans.append(i)
print(*ans, sep=' ')


input()
buttons = list(map(int, input().split()))
dirty_buttons = set(map(int, input().split()))
right_combination = []
for b in buttons:
	if b in dirty_buttons:
		right_combination.append(b)
print(*right_combination)


s = input().split()
(n, m) = (int(s[0]), int(s[1]))
a = input().split()
b = input().split()
res = ''
for x in a:
	if x in b:
		res += str(x) + ' '
print(res)


(n, m) = map(int, input().split())
li1 = []
li2 = []
li1 = list(map(int, input().split()))
li2 = list(map(int, input().split()))
count = 0
for i in range(0, n):
	for j in range(0, m):
		if li1[i] == li2[j]:
			count += 1
			if count > 1:
				print(' ', li1[i], end='')
			j = m - 1
			if count == 1:
				print(li1[i], end='')
print()


R = lambda : map(int, input().split())
(n, m) = R()
keys = list(R())
fingerprintsOn = list(R())
d = {el: idx for (idx, el) in enumerate(keys)}
l = list()
for i in fingerprintsOn:
	if i in d:
		l.append(d[i])
print(*list((keys[i] for i in sorted(l))))


p = [int(tmp) for tmp in input().split()]
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in a:
	if i in b:
		print(i, end=' ')


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
x = list(map(int, input().split()))
d = {}
for i in l:
	d.update({i: 0})
for i in x:
	try:
		d[i] += 1
	except Exception as exception:
		pass
for i in l:
	if d[i] > 0:
		print(i, end=' ')
print()


(n, m) = map(int, input().split())
os = list(map(int, input().split()))
fs = list(map(int, input().split()))
v = []
for i in range(len(os)):
	for j in range(len(fs)):
		if os[i] == fs[j]:
			v.append(os[i])
print(*v)


(n, m) = map(int, input().split())
p = list(map(int, input().split()))
o = list(map(int, input().split()))
l = []
for i in range(m):
	if o[i] in p:
		in_ = p.index(o[i])
		l.append(in_)
		l.sort()
for j in range(len(l)):
	print(p[l[j]], end=' ')


(n, m) = map(int, input().split())
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
for i in range(n):
	for j in range(m):
		if x[i] == y[j]:
			print(x[i], end=' ')
			break


(m, n) = map(int, input().split())
l = list(map(int, input().split()))
s = list(map(int, input().split()))
r = []
for i in range(m):
	if l[i] in s:
		r.append(l[i])
for i in range(len(r)):
	print(r[i], end=' ')


(n, m) = map(int, input().split())
sequence = input().split()
fingerprints = input().split()
answer = ''
for i in range(n):
	if sequence[i] in fingerprints:
		answer += sequence[i] + ' '
print(answer)


(a, b) = map(int, input().split())
c = [int(c) for c in input().split()]
d = [int(d) for d in input().split()]
e = []
m = 0
for i in range(len(c)):
	for j in range(len(d)):
		if c[i] == d[j]:
			e.append(c[i])
print(*e)


def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
(n, m) = mi()
a = li()
b = li()
for i in a:
	if i in b:
		print(i, end=' ')
print()


(n, m) = list(map(int, input().split()))
x = list(map(int, input().split()))
y = set(map(int, input().split()))
ans = []
for but in x:
	if but in y:
		ans.append(but)
print(' '.join(map(str, ans)))


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = {}
for i in b:
	if i in a:
		keys = a.index(i)
		values = a[a.index(i)]
		d[keys] = values
for i in sorted(d.keys()):
	print(d[i], end=' ')


(n, m) = [int(x) for x in input().split()]
s = [int(x) for x in input().split()]
f = [int(x) for x in input().split()]
l = []
for x in s:
	if x in f:
		l.append(str(x))
print(' '.join(l))


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(len(a)):
	if a[i] in b:
		print(a[i], end=' ')


s = list(map(int, input().split()))
n = s[0]
m = s[1]
a = list(map(int, input().split()))
b = list(map(int, input().split()))
f = []
for i in a:
	if i in b:
		f.append(i)
print(*f)


(x, y) = input().split()
keypad = list(map(int, input().split()))
prints = list(map(int, input().split()))
result = []
for i in keypad:
	if i in prints:
		result.append(i)
for j in result:
	print(j, end=' ')


(a, b) = map(int, input().split())
ls_1 = input().split()
ls_2 = input()
print(*(i for i in ls_1 if i in ls_2))


(n, m) = map(int, input().split())
a = input().split()
int_a = []
for i in range(n):
	int_a.append(int(a[i]))
b = input().split()
int_b = []
for i in range(m):
	int_b.append(int(b[i]))
ans = ''
for val in int_a:
	if val in int_b:
		ans += str(val) + ' '
print(ans)


def FingerPrints(n, m, s, f):
	res = ''
	for i in range(n):
		if s[i] in f:
			res = res + str(s[i]) + ' '
	return res
(n, m) = input().split()
s = [int(n) for n in input().split()]
f = [int(n) for n in input().split()]
print(FingerPrints(int(n), int(m), s, f))


input()
S = list(map(int, input().split()))
F = list(map(int, input().split()))
for i in S:
	if i in F:
		print(i, end=' ')


import itertools
options = input()
number_of_digits = options.split(' ')[0]
number_of_fingerprints = options.split(' ')[1]
sequence = [x for x in input().split(' ')]
buttons_with_fingerprints = [x for x in input().split(' ')]

def identifyDigits(sequence, buttons_with_fingerprints):
	comparisons = [a for (a, b) in itertools.product(sequence, buttons_with_fingerprints) if a == b]
	print(' '.join(comparisons))
identifyDigits(sequence, buttons_with_fingerprints)


map(int, input().split())
k = [int(i) for i in input().split()]
n = [int(i) for i in input().split()]
p = []
for i in n:
	if i in k:
		p = p + [[k.index(i), i]]
p = sorted(p)
for i in range(0, len(p)):
	print(p[i][1], end=' ')


def input_ints():
	return list(map(int, input().split()))

def solve():
	input()
	a = input().split()
	b = input().split()
	print(' '.join([x for x in a if x in b]))
solve()


(n, m) = map(int, input().split())
a = list(map(int, input().strip().split()))[:n]
b = list(map(int, input().strip().split()))[:m]
l3 = []
for element in a:
	if element in b:
		l3.append(element)
print(*l3)


(n, m) = [int(a) for a in input().split()]
line = [int(a) for a in input().split()]
fingerprints = set([int(a) for a in input().split()])
ans = []
for a in line:
	if a in fingerprints:
		ans.append(a)
for a in ans:
	print(a, end=' ')


(n, m) = input().split()
a = input().split()
b = input().split()
ans = [i for i in a if i in b]
print(' '.join(ans))


def main():
	(n, m) = map(int, input().split())
	seq = list(map(int, input().split()))
	fing = set(list(map(int, input().split())))
	res = list()
	for v in seq:
		if v in fing:
			res.append(v)
	print(' '.join(map(str, res)))
main()


(m, n) = map(int, input().split())
l = list(map(int, input().split()))
o = list(map(int, input().split()))
for w in l:
	if w in o:
		print(w, end=' ')


(a, b) = map(int, input().split())
m = list(map(int, input().split()))
n = list(map(int, input().split()))
for x in range(a):
	if m[x] in n:
		print(m[x], end=' ')


(n, m) = map(int, input().split())
seq = [int(i) for i in input().split()][:n]
f = [int(i) for i in input().split()][:m]
a = []
for i in range(n):
	for j in range(m):
		if seq[i] == f[j]:
			a.append(seq[i])
for i in range(len(a)):
	print(a[i], end=' ')


nm = input().split()
n = int(nm[0])
m = int(nm[1])
arr = list(map(int, input().rstrip().split()))
ar = list(map(int, input().rstrip().split()))
for i in arr:
	if i in ar:
		print(i, end=' ')
		ar.remove(i)


(n, m) = tuple(map(lambda x: int(x), input().split(' ')))
ns = list(map(lambda x: int(x), input().split()))
ms = list(map(lambda x: int(x), input().split()))
ms = set(ms)

def generate_subs(arr):
	opsize = 2 ** len(arr)
	for counter in range(1, int(opsize)):
		out = []
		for j in range(0, n):
			if counter & 1 << j:
				out.append(arr[j])
		yield out
curr = 0
out = []
for subc in generate_subs(ns):
	s = set(subc)
	t = s.intersection(ms)
	if len(t) > curr:
		out = subc
		curr = len(t)
if len(out) == 0:
	print()
else:
	out = ' '.join(map(lambda x: str(x), out))
	print(out)


(n, m) = map(int, input().split())
N = [int(i) for i in input().split()]
M = [int(i) for i in input().split()]
ans = []
for lt in N:
	if lt in M:
		ans.append(lt)
		print(ans[-1], end=' ')


(n, m) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()][:n]
b = [int(x) for x in input().split()][:m]
flag = 0
for i in a:
	if i in b:
		flag += 1
		print(i, end=' ')
		if flag == m:
			break


(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = set(list(map(int, input().split())))
ans = []
for i in range(n):
	if a[i] in b:
		ans.append(a[i])
print(*ans)


(n, m) = map(int, input().split())
seq = list(map(int, input().split()))
fing = list(map(int, input().split()))
lists = []
for i in seq:
	for j in fing:
		if j == i:
			print(j, end=' ')


(u, v) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = ''
for i in range(u):
	if a[i] in b:
		res += str(a[i]) + ' '
print(res)


(n, m) = map(int, input().split())
l = [int(i) for i in input().split()]
res = []
l1 = [int(i) for i in input().split()]
for i in l:
	if i in l1:
		res.append(i)
print(*res)


I = lambda : map(int, input().split())
(n, m) = I()
a = list(I())
f = list(I())
for _ in a:
	if _ in f:
		print(_, end=' ')


(n, m) = map(int, input().split(' '))
xs = list(map(int, input().split(' ')))
ys = set(map(int, input().split(' ')))
print(*[x for x in xs if x in ys])


(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
lst = []
for i in range(len(a)):
	if a[i] in b:
		lst.append(a[i])
if len(lst) == 0:
	pass
else:
	print(*lst)


(n, m) = [int(i) for i in input().split()]
arr1 = [int(i) for i in input().split()]
arr2 = [int(i) for i in input().split()]
for i in range(len(arr1)):
	for j in range(len(arr2)):
		if arr1[i] == arr2[j]:
			print(arr2[j], end=' ')


(n, m) = map(int, input().split())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l = []
for i in range(0, n):
	for j in range(0, m):
		if l1[i] == l2[j]:
			l.append(l1[i])
for i in range(0, len(l)):
	print(l[i], end=' ')


a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
Indx = []
for i in c:
	if i in b:
		Indx.append(b.index(i))
Indx.sort()
for i in Indx:
	print(b[i], end=' ')


(n, m) = map(int, input().split())
nlst = input().split()
mlst = input().split()
for j in range(n):
	if nlst[j] in mlst:
		print(nlst[j], end=' ')


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for i in b:
	if i in a:
		c.append(a.index(i))
c.sort()
d = []
for i in c:
	d.append(a[i])
print(*d, end=' ')


(n, m) = [int(x) for x in input().split()]
x = [int(x_) for x_ in input().split()]
y = [int(x_) for x_ in input().split()]
res = ''
for el in x:
	if el in y:
		res += str(el) + ' '
print(res[:-1])


(n, m) = map(int, input().split())
s = list(map(int, input().split()))
f = list(map(int, input().split()))
a = ''
for i in range(len(s)):
	if s[i] in f:
		a += str(s[i])
print(' '.join(a))


def max1(a):
	p = a[0]
	for x in a:
		if x > p:
			p = x
	return p

def prlist(a):
	for x in a:
		print(x, end=' ')
(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for i in range(n):
	if a[i] in b:
		c.append(a[i])
prlist(c)


result = []
(n, m) = map(int, input().split())
list1 = list(map(int, input().split()))
list2 = list(map(int, input().split()))
for m in list1:
	if m in list2:
		result.append(m)
for m in result:
	print(m, end=' ')


(n, m) = map(int, input().split())
x = [*map(int, input().split())]
y = [*map(int, input().split())]
flg = False
for xi in x:
	if xi in y:
		if flg:
			print(' ', end='')
		print(xi, end='')
		flg = True
print()


(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = set(list(map(int, input().split())))
res = []
for i in range(n):
	if a[i] in b:
		res.append(a[i])
print(' '.join(list(map(str, res))))


s = [int(i) for i in input().split(' ')]
n = s[0]
m = s[1]
t = []
x = [int(n) for n in input().split(' ')]
y = [int(m) for m in input().split(' ')]
for i in range(len(x)):
	for j in range(len(y)):
		if x[i] == y[j]:
			t.append(x[i])
print(' '.join(map(str, t)))


(n, m) = map(int, input().split())
val = list(map(int, input().split()))
num = list(map(int, input().split()))
d = {v: i for (i, v) in enumerate(val)}
num = [v for v in num if v in d]
num.sort(key=lambda x: d[x])
print(*num)


(n, m) = list(map(int, input().split()))
arr1 = input()
arr2 = input()
s = ''
for i in range(2 * n - 1):
	if i % 2 == 0:
		if arr2.find(arr1[i]) != -1:
			s = s + arr1[i] + ' '
print(s)


(n, m) = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
code = []
for i in range(n):
	for j in range(m):
		if x[i] == y[j]:
			code.append(x[i])
print(' '.join((str(a) for a in code)))


(n, m) = map(int, input().split())
ans = [-1] * 10
x = list(map(int, input().split()))
d = dict()
for i in range(len(x)):
	d[x[i]] = i
y = list(map(int, input().split()))
for i in y:
	if i in x:
		ans[d[i]] = i
for i in ans:
	if i != -1:
		print(i, end=' ')


import math
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
c = list(map(int, input().strip().split(' ')))
d = list(map(int, input().strip().split(' ')))
for x in range(0, len(c)):
	if c[x] not in d:
		c[x] = -1
for x in range(0, len(c)):
	if c[x] != -1:
		print(c[x], end=' ')
print()


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
c = list(map(int, input().split()))
res = []
for ch in a:
	if ch in c:
		res.append(c.pop(c.index(ch)))
print(*res)


import math
import heapq

def getIntList():
	return list(map(int, input().split()))

def getTransIntList(n):
	first = getIntList()
	m = len(first)
	result = [[0] * n for _ in range(m)]
	for i in range(m):
		result[i][0] = first[i]
	for j in range(1, n):
		curr = getIntList()
		for i in range(m):
			result[i][j] = curr[i]
	return result
(n, m) = getIntList()
x = getIntList()
y = getIntList()
flag = [False] * 10
for n in y:
	flag[n] = True
result = []
for valX in x:
	if flag[valX]:
		result.append(valX)
print(' '.join(map(str, result)))


(n, m) = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
lis = []
for i in range(len(t)):
	if t[i] in s:
		lis.append(s.index(t[i]))
lis.sort()
for i in range(len(lis)):
	print(s[lis[i]], end=' ')


(n, m) = map(int, input().split())
m = list(map(int, input().split()))
p = list(map(int, input().split()))
for i in m:
	if i in p:
		print(i, end=' ')


(n, m) = map(int, input().split())
p = [int(x) for x in input().split()]
q = [int(x) for x in input().split()]
for x in p:
	for y in q:
		if y == x:
			print(x, end=' ')


(n, m) = map(int, input().split())
seq = list(map(int, input().split()))
fin = list(map(int, input().split()))
ans = []
for i in seq:
	if i in fin:
		ans.append(i)
print(*ans)


(n, m) = [int(x) for x in input().split()]
if n != 0:
	a = list(map(int, input().split()))
if m != 0 and n != 0:
	b = list(map(int, input().split()))
	ans = []
	for i in a:
		if i in b:
			ans.append(i)
	print(' '.join((str(e) for e in ans)))


(n, m) = map(int, input().split())
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
z = []
for i in x:
	if i in y and i not in z:
		z.append(i)
print(*z)


(a1, a2) = map(int, input().split())
x = input().split()
y = input().split()
for i in range(a1):
	for j in range(a2):
		if x[i] == y[j]:
			print(x[i], end=' ')


(n, m) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
ans = ''
for i in range(0, n):
	if a[i] in b:
		ans += str(a[i]) + ' '
print(ans)


s = input().strip()
(n, m) = list(map(int, s.split()))
x = list(map(int, input().strip().split()))
y = list(map(int, input().strip().split()))
y = set(y)
ans = []
for a in x:
	if a in y:
		ans.append(a)
print(' '.join(map(str, ans)))


(n, m) = map(int, input().split())
a = [*map(int, input().split())]
b = set([*map(int, input().split())])
for i in a:
	if i in b:
		print(i, end=' ')


(n, m) = list(map(int, input().split()))
x = list(map(int, input().split()[:n]))
y = list(map(int, input().split()[:m]))
b = []
for i in x:
	if i in y:
		b.append(i)
for i in b:
	print(i, end=' ')


(n, m) = map(int, input().split())
nArr = list(map(int, input().split()))
mArr = list(map(int, input().split()))
for i in nArr:
	if i in mArr:
		print(i, end=' ')


(u, v) = input().split()
x = int(u)
y = int(v)
a = input().split()
b = input().split()
for i in range(x):
	for j in range(y):
		if a[i] == b[j]:
			print(a[i], end='')
			print(' ', end='')
			break


R = lambda : map(int, input().split())
(n, m) = R()
(x, y) = (R(), set(R()))
print(*(u for u in x if u in y))


(n, m) = map(int, input().split())
ai = list(map(int, input().split()))
bi = list(map(int, input().split()))
for i in ai:
	if i in bi:
		print(i, end=' ')


(a, n) = map(int, input().split())
sequence = list(input().split())
finger = list(input().split())
list1 = [i for i in sequence if i in finger]
print(*list1)


(a, b) = map(int, input().split())
y = [int(i) for i in input().split()]
g = {i for i in input().split()}
s = []
for i in range(a):
	if str(y[i]) in g:
		s.append(y[i])
for i in range(len(s)):
	print(s[i], end=' ')


(n, m) = [int(x) for x in list(input().split())]
a = [int(x) for x in list(input().split())]
b = [int(x) for x in list(input().split())]
s = ''
for i in range(0, n):
	if a[i] in b:
		print(a[i], ' ')


a = input().split()
b = input().split()
c = input().split()
h = 0
for i in range(int(a[0])):
	n = 0
	for j in range(int(a[1])):
		if b[h] != c[j]:
			n += 1
	if n == int(a[1]):
		b.remove(b[h])
	else:
		h += 1
for i in range(int(len(b))):
	print(b[i], end=' ')


(n, m) = (int(x) for x in input().split())
x_list = list((int(x) for x in input().split()))
y_list = list((int(x) for x in input().split()))
for x in x_list:
	if x in y_list:
		print(x, end=' ')


(n, m) = map(int, input().split())
(y, y1) = ([], [])
l = list(map(int, input().split()))
x = list(map(int, input().split()))
for i in range(len(x)):
	if x[i] in l:
		y.append(l.index(x[i]))
y.sort()
for i in range(len(y)):
	y1.append(l[y[i]])
print(*y1)


(n, m) = map(int, input().split())
n_list = list(map(int, input().split()))
m_list = list(map(int, input().split()))
ans = []
for item in n_list:
	if item in m_list:
		ans.append(item)
print(' '.join([str(x) for x in ans]))


(n, m) = map(int, input().split())
x = [i for i in map(int, input().split())]
y = [i for i in map(int, input().split())]
seq = []
for i in y:
	if i not in x:
		pass
	else:
		z = x.index(i)
		seq.append(z)
seq.sort()
for i in seq:
	print(x[i], end=' ')


a = input().split()
b = list(map(int, input().split()))
c = list(map(int, input().split()))
lis = []
for i in b:
	for j in c:
		if i == j:
			lis.append(j)
print(*lis)


(n, m) = input().split()
sequence = input().split()
finger = tuple(input().split())
for i in sequence:
	if i in finger:
		print(i, end=' ')


from sys import stdin, stdout, exit as sys_ret
(f_input, f_print, f_flush) = (stdin.readline, stdout.write, stdout.flush)
(length, amount) = map(int, f_input().split())
(seq, touched) = ([int(_) for _ in f_input().split()], {int(__) for __ in f_input().split()})
for i in seq:
	if i in touched:
		f_print(str(i) + ' ')


(a, b) = map(int, input().split())
c = list(map(int, input().split()))
d = list(map(int, input().split()))
e = []
for i in range(len(c)):
	for j in range(len(d)):
		if c[i] == d[j]:
			e.append(i)
for i in range(len(e)):
	print(c[e[i]], end=' ')


string = input().split(' ')
n = int(string[0])
m = int(string[1])
sequence = input().split(' ')
fp = input().split(' ')
pw = []
for item in sequence:
	if item in fp:
		pw.append(item)
print(' '.join(pw))


(_, l, s) = (input().split() for _ in '_ls')
print(*[d for d in l if d in s])


(n, m) = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
res = []
for i in l:
	if i in a:
		res.append(i)
print(*res, sep=' ')


(n, m) = map(int, input().split(' '))
x1 = list(map(int, input().split(' ')))
y1 = list(map(int, input().split(' ')))
a = []
for i in range(n):
	if x1[i] in y1:
		a.append(x1[i])
	else:
		continue
print(*a)


(n, m) = map(int, input().split())
a = list(input().split())
b = list(input().split())
p = []
for i in a:
	for j in b:
		if i == j:
			p += [i]
print(' '.join(p))


(m, n) = map(int, input().split())
a = input().split()
c = input().split()
for i in a:
	if i in c:
		print(i, end=' ')


import sys
(n, m) = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
for i in x:
	if i in y:
		print(i, end=' ')


import operator

def fingerprints(n, m, ls1, ls2):
	dic = {}
	for i in range(m):
		if ls2[i] in ls1:
			dic.update({ls1.index(ls2[i]): ls2[i]})
	dic = dict(sorted(dic.items(), key=operator.itemgetter(0)))
	ls = list(dic.values())
	return ls
(n, m) = input().split()
n = int(n)
m = int(m)
ls1 = [int(i) for i in input().split()]
ls2 = [int(j) for j in input().split()]
print(' '.join(map(str, fingerprints(n, m, ls1, ls2))))


n = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
l1 = [int(i) for i in input().split()]
ans = ''
for i in l:
	if i in l1:
		ans += str(i) + ' '
print(ans)


import sys
import math
(a, b) = map(int, input().split())
c = list(map(int, input().split()))
d = list(map(int, input().split()))
e = []
for i in c:
	if i in d:
		e.append(i)
print(*e)


while True:
	(n, m) = map(int, input().split(' '))
	if 1 <= n and n <= 10 and (1 <= m) and (m <= 10):
		break
while True:
	input_1 = input().split(' ')
	if len(input_1) == n:
		break
while True:
	input_2 = input().split(' ')
	if len(input_2) == m:
		break
X = []
Y = []
X = [int(x) for x in input_1]
Y = [int(y) for y in input_2]
Z = []
for x in X:
	for y in Y:
		if x == y:
			Z.append(x)
print(*Z)


import math
import os
import random
import re
from sys import stdin, stdout
from collections import Counter
from itertools import permutations

def si():
	return str(stdin.readline())

def ii():
	return int(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def li():
	return list(mi())

def debug(x):
	return stdout.write(str(x))
(a, b) = mi()
arr = li()
fp = li()
ans = []
for i in arr:
	if i in fp:
		ans.append(i)
print(' '.join((str(e) for e in ans)))


(n, m) = map(int, input().split())
ar0 = [int(i) for i in input().split()]
ar1 = [int(i) for i in input().split()]
ar3 = []
for i in range(n):
	if ar0[i] in ar1:
		ar3.append(ar0[i])
print(' '.join([str(i) for i in ar3]))


__file__ = __file__.startswith('/home/a_farazei')

def input_():
	global __file__
	if not __file__:
		return input()
	if not hasattr(__file__, 'readline'):
		__file__ = open('input.txt', 'r')
	return __file__.readline()
(n, m) = map(int, input_().split())
a = list(map(int, input_().split()))
b = set(map(int, input_().split()))
print(' '.join((str(x) for x in a if x in b)))


(m, n) = input().split()
(m, n) = [int(m), int(n)]
seq = input().split()
key = input().split()
for i in seq:
	if i in key:
		print(i, end=' ')


(n, m) = map(int, input().split())
sequence = list(map(int, input().split()))
fingerprints = list(map(int, input().split()))
res = []
for x in sequence:
	if x in fingerprints:
		res.append(x)
for x in res:
	print(x, end=' ')


(n, m) = map(int, input().split())
N = [int(x) for x in input().split()]
M = [int(x) for x in input().split()]
F = []
for it in N:
	if it in M:
		F.append(it)
print(*F)


(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
t = [False] * n
b = list(map(int, input().split()))
for i in range(m):
	for j in range(n):
		if a[j] == b[i]:
			t[j] = True
for i in range(n):
	if t[i]:
		print(a[i], end=' ')


(n, m) = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
for i in range(len(p)):
	if p[i] in q:
		print(p[i], end=' ')


(n, m) = map(int, input().split())
c = map(str, input().split())
f = map(str, input().split())
l1 = list(c)
l2 = list(f)
ans = ''
i = 0
for j in range(n):
	if l1[i] in l2:
		ans += l1[i] + ' '
	i += 1
print(ans)


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
ans = []
for i in a:
	if i in b:
		ans.append(str(i))
print(' '.join(ans))


(n, m) = map(int, input().split())
ln = list(map(int, input().split()))
lm = list(map(int, input().split()))
a = []
for item in ln:
	if item in lm:
		a.append(item)
for item in a:
	print(item, end=' ')


(n, m) = map(int, input().split())
password = []
a = input().split()
b = input().split()
for i in a:
	if i in b:
		password.append(i)
print(*password)


input()
a = map(int, input().split())
print(*filter(list(map(int, input().split())).count, a), sep=' ')


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = []
for i in a:
	if i in b:
		res.append(i)
for i in res:
	print(i, end=' ')


(a, b) = map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
a = []
for i in range(len(arr2)):
	for j in range(len(arr1)):
		if arr2[i] == arr1[j]:
			a.append(j)
a.sort()
for i in a:
	print(arr1[i], end=' ')


(n, m) = [int(x) for x in input().split()]
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
for i in l1:
	for j in l2:
		if i == j:
			print(i, end=' ')


import sys
input = sys.stdin.readline
L = lambda : list(map(int, input().split()))
(n, m) = map(int, input().split())
l = L()
k = L()
g = []
for i in k:
	if i in l:
		g.append(l.index(i))
g.sort()
for i in g:
	print(l[i], end=' ')


(n, m) = map(int, input().split())
seq = [int(num) for num in input().split()]
fp = [int(num) for num in input().split()]
code = []
for i in seq:
	for k in fp:
		if i == k:
			code.append(i)
for i in code:
	print(i, end=' ')


(n, m) = map(int, input().split())
an = list(input().split())
am = input()
print(''.join([i + ' ' for i in an if i in am]))


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
ll = list(map(int, input().split()))
s = ''
for i in range(len(l)):
	if l[i] in ll:
		s += str(l[i]) + ' '
print(s)


(n, m) = map(int, input().split())
xL = [int(x) for x in input().split()]
yL = [int(x) for x in input().split()]
ansL = []
for i in xL:
	if i in yL:
		ansL.append(i)
print(*ansL)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
k = list(map(int, input().split()))
p = []
u = []
for i in k:
	for j in l:
		if i == j:
			p.append(l.index(i) + 1)
		else:
			pass
p.sort()
s = []
for q in p:
	q -= 1
	s.append(q)
for b in s:
	print(l[b], end=' ')


(n, m) = map(int, input().split())
Arr = list(map(int, input().split()))
Finger = list(map(int, input().split()))
for i in range(n):
	for j in range(m):
		if Arr[i] == Finger[j]:
			print(Finger[j], end=' ')
print()


s = input().split(' ')
a = input().split(' ')
b = input().split(' ')
for i in a:
	if i in b:
		print(i, end=' ')


(n, m) = map(int, input().strip().split(' '))
x = list(map(int, input().strip().split(' ')))
y = list(map(int, input().strip().split(' ')))
res = []
for i in x:
	if i in y:
		res.append(i)
print(' '.join([str(j) for j in res]))


a = input().split(' ')
n = int(a[0])
m = int(a[1])
b = input().split(' ')
p = input().split(' ')
i = 0
while i < n:
	b[i] = int(b[i])
	i = i + 1
i = 0
while i < m:
	p[i] = int(p[i])
	i = i + 1
i = 0
c = []
while i < n:
	j = 0
	while j < m:
		if b[i] == p[j]:
			c = c + [p[j]]
		j = j + 1
	i = i + 1
i = 0
s = ''
while i < len(c):
	s = s + str(c[i]) + ' '
	i = i + 1
print(s)


(n, m) = tuple(map(int, input().split()))
keys = list(map(int, input().split()))
keys_with_fingers = set(map(int, input().split()))
code = list()
for k in keys:
	if k in keys_with_fingers:
		code.append(str(k))
print(' '.join(code))


(n, m) = map(int, input().split())
pos = [int(elem) for elem in input().split()]
fings = set()
fing = [fings.add(int(elem)) for elem in input().split()]
for i in range(n):
	if pos[i] in fings:
		print(pos[i], end=' ')


lengths = input()
lengths = lengths.split(' ')
sequence = input()
sequence = sequence.split(' ')
fingerprints = input()
fingerprints = fingerprints.split(' ')
sequence = list(map(int, sequence))
fingerprints = list(map(int, fingerprints))
fingerArray = []
i = 0
for i in range(0, 10):
	if i in fingerprints:
		fingerArray.append(True)
	else:
		fingerArray.append(False)
	i = i + 1
result = ''
for x in sequence:
	if fingerArray[x]:
		result += str(x)
		result += ' '
print(result)


(n, m) = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
for i in range(n):
	if y.count(x[i]):
		print(x[i], end=' ')


(n, m) = map(int, input().split())
ans = ''
x = [0] * n
y = [0] * m
x = input().split()
y = input().split()
for i in range(n):
	x[i] = int(x[i])
for i in range(m):
	y[i] = int(y[i])
i = 0
j = 0
while j < m and i < n:
	if x[i] in y:
		ans = ans + str(x[i]) + ' '
		j += 1
	i += 1
print(ans)


(n, m) = [int(x) for x in input().split()]
list1 = [int(x) for x in input().split()]
list2 = [int(x) for x in input().split()]
d = []
for i in list2:
	try:
		d.append(list1.index(i, 0, len(list1)))
	except:
		d.append(-1)
d.sort()
for i in d:
	if i >= 0:
		print(list1[i], end=' ')


(n, m) = map(int, input().split())
l1 = input().split()
l2 = input().split()
for i in range(n):
	if l1[i] in l2:
		print(l1[i], end=' ')


from math import ceil, log
t = 1
for test in range(t):
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = []
	for key in a:
		if key in b:
			ans.append(key)
	print(*ans)


(n, m) = map(int, input().split())
num = [int(i) for i in input().split()]
f = [int(i) for i in input().split()]
for item in num:
	if item in f:
		print(item, end=' ')


(n, m) = map(int, input().split())
x = list(map(int, input().split()))[:n]
y = list(map(int, input().split()))[:m]
new = []
for i in x:
	for j in y:
		if i == j:
			new.append(i)
for i in new:
	print(i, end=' ')


[n, m] = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
arr = [False] * n
for i in range(m):
	for j in range(n):
		if c[i] == p[j]:
			arr[j] = True
			break
for i in range(n):
	if arr[i] == True:
		print(p[i], end=' ')


[n, m] = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
for e in a:
	if e in b:
		print(e, end=' ')


(n, m) = map(int, input().split())
a = [int(X) for X in input().split()]
b = [int(x) for x in input().split()]
an = []
for i in a:
	if i in b:
		an.append(i)
print(*an)


a = list(map(int, input().split()))
b = [0, 0]
for i in range(0, 2):
	b[i] = list(map(int, input().split()))
d = []
for j in range(0, a[1]):
	for k in range(0, a[0]):
		if b[1][j] == b[0][k]:
			d.append([k, b[1][j]])
d.sort()
g = len(d)
for u in range(0, g):
	print(d[u][1], end=' ')


(n, m) = [int(n) for n in input().split()]
arr = [int(item) for item in input().split()]
brr = [int(item) for item in input().split()]
crr = [False] * 10
drr = []
for j in brr:
	crr[j] = True
for i in arr:
	if crr[i] == True:
		drr.append(i)
print(*drr)


lst = list(map(int, input().split()))
lst1 = list(map(int, input().split()))
lst2 = list(map(int, input().split()))
for e in lst1:
	if e in lst2:
		print(e, end=' ')


A = input()
B = input().split(' ')
C = input().split(' ')
for i in B:
	if i in C:
		print(i, end=' ')


(n, m) = map(int, input().split())
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
r = []
for i in y:
	if i in x:
		r.append(x.index(i))
r.sort()
print(' '.join((str(x[i]) for i in r)))


n = list(map(int, input().split()))
m = list(map(int, input().split()))
k = list(map(int, input().split()))
l = []
for i in m:
	for j in k:
		if i == j:
			l.append(i)
print(*l)


from math import ceil

def main():
	(n, m) = [int(v) for v in input().split()]
	pos = [int(v) for v in input().split()]
	otp = set([int(v) for v in input().split()])
	d = []
	for v in pos:
		if v in otp:
			d.append(str(v))
	print(' '.join(d))
main()


(a, b) = input().split()
li = list(map(int, input().split()))
test = list(map(int, input().split()))
ans = []
for i in li:
	if i in test:
		ans.append(i)
for i in ans:
	print(i, end=' ')


(n, m) = [int(_) for _ in input().split()]
x1 = [int(_) for _ in input().split()]
x2 = [int(_) for _ in input().split()]
for i in x1:
	if i in x2:
		print(i, end=' ')


(n, m) = map(int, input().split())
line1 = input().split()
line2 = input().split()
for i in line1:
	if i in line2:
		print(i, end=' ')


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
f = list(map(int, input().split()))
for i in range(n):
	if l[i] in f:
		print(l[i], end=' ')


[n, m] = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
ans = []
while x:
	if x[-1] in y:
		ans.append(x.pop())
	else:
		x.pop()
ans.reverse()
for i in ans:
	print(i, end=' ')


import sys
finger = [False] * 10
(n, m) = map(int, input().split())
keys = map(int, input().split())
fingers = map(int, input().split())
for f in fingers:
	finger[f] = True
for key in keys:
	if finger[key]:
		print(key, ' ', end='')
print()


a = input().split()
n = int(a[0])
m = int(a[1])
a = input().split()
b = set(input().split())
ans = []
for i in range(n):
	if a[i] in b:
		ans.append(a[i])
print(' '.join(ans))


(n, m) = input().split()
x = input().replace(' ', '')
y = input()
for i in x:
	if i in y:
		print(i, end=' ')


(n, m) = map(int, input().split())
general = list(map(int, input().split()))
fingers = list(map(int, input().split()))
for item in general:
	for jtem in fingers:
		if item == jtem:
			print(item, end=' ')


(n, m) = map(int, input().split())
s = list(map(int, input().split()))
p = list(map(int, input().split()))
k = ''
for i in s:
	if i in p:
		k += str(i) + ' '
print(k)


(n, m) = map(int, input().strip().split())
l = list(map(int, input().strip().split()))
l1 = list(map(int, input().strip().split()))
for i in l:
	if i in l1:
		print(i, end=' ')
print()


(n, m) = map(int, input().split())
X = list(map(int, input().split()))
Y = set(map(int, input().split()))
R = []
for x in X:
	if x in Y:
		R.append(x)
print(' '.join([str(x) for x in R]))


t = input()
t = t.split(' ')
n = int(t[0])
m = int(t[1])
t = input()
t = t.split(' ')
arr = []
for i in t:
	arr.append(int(i))
t = input()
t = t.split(' ')
arr1 = {-2}
for i in t:
	arr1.add(int(i))
ans = ''
for k in arr:
	if arr1.__contains__(k):
		ans = ans + str(k)
		ans = ans + ' '
print(ans)


(n, m) = map(int, input().strip().split())
a = [int(_) for _ in input().strip().split()]
b = [int(_) for _ in input().strip().split()]
b = set(b)
ans = [i for i in a if i in b]
print(*ans)


(n, m) = map(int, input().split())
digits = list(map(int, input().split()))
keys = list(map(int, input().split()))
for key in [digit_each for digit_each in digits for key_each in keys if digit_each == key_each]:
	print(key, end=' ')


F = lambda : map(int, input().split())
F()
a = F()
b = list(F())
d = []
for c in a:
	if c in b:
		d.append(c)
print(*d, ' ')


import sys
import math
Input = sys.stdin.readline
get_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline())
input()
a = get_list()
b = get_list()
for i in a:
	if i in b:
		print(i, end=' ')


a = list(map(int, input().split(' ')))
n = a[0]
m = a[1]
d = {}
b = list(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))
for i in range(m):
	for j in range(n):
		if c[i] == b[j]:
			d[j] = c[i]
e = sorted(d.keys())
for i in e:
	print(d[i], end=' ')


[n, m] = [int(x) for x in input().split()]
S = [int(x) for x in input().split()]
F = [int(x) for x in input().split()]
for i in S:
	if i in F:
		print(i, end=' ')


(m, n) = map(int, input().split(' '))
x = [int(s) for s in input().split(' ')]
y = [int(s) for s in input().split(' ')]
out = ''
for i in x:
	if y.count(i):
		out += str(i)
		out += ' '
print(out)


(n, m) = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [x for x in A if x in B]
print(' '.join(map(str, C)))


(n, m) = [int(t) for t in input().split()]
x = [int(t) for t in input().split()]
y = [int(t) for t in input().split()]
x = filter(lambda t: t in y, x)
print(' '.join(map(lambda t: str(t), x)))


(n, m) = map(int, input().split())
seq = list(map(int, input().split()))
fing = list(map(int, input().split()))
arr = []
for i in seq:
	if i in fing:
		arr.append(i)
if arr:
	print(*arr, sep=' ')
else:
	print()


n = [int(num) for num in input().split()]
a = {}
b = {}
count = 1
for j in input().split():
	(a[j], count) = (count, count + 1)
for j in input().split():
	b[j] = 0
for i in a.keys():
	try:
		if b[i] == 0:
			print(i, end=' ')
	except KeyError:
		pass


(n, m) = input().split(' ')
n = int(n)
m = int(m)
s = input().split(' ')
num = input().split(' ')
nw = []
i = 0
while i < n:
	if s[i] in num:
		nw.append(s[i])
	i += 1
print(' '.join(nw))


(n, m) = map(int, input().split())
List_n = list(map(int, input().split()))
del List_n[n:]
List_m = list(map(int, input().split()))
del List_m[m:]
List1 = []
for i in List_m:
	if i in List_n:
		List1.append(i)
List2 = []
for i in range(len(List1)):
	List2.append(List_n.index(List1[i]))
List2.sort(reverse=False)
for i in List2:
	print(List_n[i], end=' ')


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = []
for i in range(n):
	if a[i] in b:
		x.append(a[i])
print(*x)


(k, l) = map(int, input().split())
ls = list(map(int, input().split()))
ls2 = list(map(int, input().split()))
l = []
for i in range(len(ls)):
	if ls2.count(ls[i]):
		l.append(ls[i])
for x in l:
	print(x, end=' ')


(n, m) = [int(i) for i in input().split()]
seq = [int(i) for i in input().split()]
fingerprints = set((int(i) for i in input().split()))
res = []
for i in seq:
	if i in fingerprints:
		res.append(i)
print(*res, sep=' ')


(n, m) = input().split()
seq = list(map(int, input().split()))
ch = list(map(int, input().split()))
for ele in seq:
	if ele in ch:
		print(ele, '', end='')
print()


(n, m) = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
key = []
for item in x:
	if item in y:
		key.append(item)
print(*key)


(n, m) = map(int, input().split())
seq = list(map(int, input().split()))
fri = list(map(int, input().split()))
result = []
dic_seq = {}
for i in range(len(seq)):
	dic_seq[seq[i]] = i
for i in range(len(fri)):
	if fri[i] in dic_seq:
		result.append([fri[i], dic_seq[fri[i]]])
result.sort(key=lambda x: x[1])
if result == []:
	print()
else:
	for i in range(len(result) - 1):
		print(result[i][0], end='')
		print(' ', end='')
	print(result[-1][0])


header = input()
header = [int(i) for i in header.split()]
nums = input()
nums = [int(i) for i in nums.split()]
targets = input()
targets = [int(i) for i in targets.split()]
out = []
for i in range(len(nums)):
	if nums[i] in targets:
		out.append(nums[i])
print(' '.join([str(o) for o in out]))


(n, m) = map(int, input().split())
sequence = input().split()
sequence = list(map(int, sequence))
nsequencer = sequence
fingerprints = input().split()
fingerprints = list(map(int, fingerprints))
s = ''
for i in sequence:
	if i in fingerprints:
		s = s + str(i) + ' '
print(s)


from sys import stdin, stdout

def rint():
	return map(int, stdin.readline().split())
(n, m) = rint()
x = list(rint())
y = set(rint())
ans = []
for xx in x:
	if xx in y:
		ans.append(xx)
print(*ans)


(n, m) = map(int, input().split())
n = list(map(int, input().split()))
m = list(map(int, input().split()))
for i in n:
	try:
		s = m.index(i)
		print(i, end=' ')
	except:
		s = 1
print('')


(key_sequence, key_fingerprints) = input().split(' ')
(key_sequence, key_fingerprints) = (int(key_sequence), int(key_fingerprints))
pin_sequence = []
pin_fingerprints = []
pin_sequence = input().split(' ')
pin_fingerprints = input().split(' ')
pin = []
for i in pin_sequence:
	for j in pin_fingerprints:
		if i == j:
			pin.append(i)
for i in pin:
	print(i, end=' ')


(n, k) = list(map(int, input().split()))
nums = input().split()
fprint = input().split()
a = []
for i in range(n):
	if nums[i] in fprint:
		a.append(nums[i])
print(' '.join(a))


(x, y) = map(int, input().split())
data = list(map(int, input().split()))
key = list(map(int, input().split()))
newData = []
for sequence in range(len(data)):
	if data[sequence] in key:
		newData.append(data[sequence])
print(*newData)


(n, m) = list(map(int, input().split()))
ln = list(map(int, input().split()))
lm = list(map(int, input().split()))
s1 = set(lm).intersection(set(ln))
l = []
for i in s1:
	l.append(ln.index(i))
l.sort()
for i in l:
	print(ln[i], end=' ')


(n, m) = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
ay = []
for i in y:
	if i in x:
		ay.append(i)
if len(ay) == 0:
	print()
index = []
for i in ay:
	for j in range(n):
		if x[j] == i:
			index.append(j)
index.sort()
for i in index:
	print(x[i], end=' ')


def prA(arr, kuni):
	arrr = []
	for i in kuni:
		if i in arr:
			arrr.append(arr.index(i))
	arrr.sort()
	for a in arrr:
		print(arr[a], end=' ')
ar = list(map(int, input().rstrip().split()))
n = ar[0]
m = ar[1]
arr = list(map(int, input().rstrip().split()))
kuni = list(map(int, input().rstrip().split()))
prA(arr, kuni)


x = []
(n, s) = map(int, input().split())
f = list(map(int, input().split()))
l = list(map(int, input().split()))
for i in range(len(f)):
	if f[i] in l:
		x.append(f[i])
print(*x)


[n, m] = map(int, input().strip().split())
ais = list(map(int, input().strip().split()))
bis = set(map(int, input().strip().split()))
cis = list(filter(lambda k: k in bis, ais))
print(' '.join(map(str, cis)))


input()
(ns1, ns2) = (input().split(' '), input().split(' '))
for el in ns1:
	if el in ns2:
		print(el, end=' ')


f = lambda : map(int, input().split())
(n1, n2) = f()
l1 = list(f())
l2 = list(f())
ind = []
for i in l2:
	if i in l1:
		ind.append(l1.index(i))
ind.sort()
[print(l1[i], end=' ') for i in ind if i != -1]


(n, m) = map(int, input().split())
arr = input()
ar1 = list(map(int, arr.split(' ')))
arrr = input()
ar2 = list(map(int, arrr.split(' ')))
ar3 = []
for i in range(len(ar1)):
	if ar1[i] in ar2:
		ar3.append(i)
if len(ar3) == 0:
	print()
else:
	for j in ar3:
		print(ar1[j], end=' ')


(n, m) = map(int, input().split())
seq = map(int, input().split())
finger = list(map(int, input().split()))
ans = []
for i in seq:
	if i in finger:
		ans.append(i)
print(' '.join(map(str, ans)))


def find(a):
	global AA
	for i in range(len(AA)):
		if AA[i] == int(a):
			AA = AA[:i] + AA[i + 1:]
			return 1
	return 0

def find1(a):
	for i in range(len(B)):
		if B[i] == a:
			return 1
	return 0
aaaaaaaaaaaaaa = input()
a = input() + ' '
b = ''
A = []
for j in range(len(a)):
	if a[j] == ' ':
		A.append(int(b))
		b = ''
	else:
		b += a[j]
AA = A[:]
a1 = input() + ' '
b1 = ''
B = []
for j in range(len(a1)):
	if a1[j] == ' ':
		if find(b1) == 1:
			B.append(int(b1))
		b1 = ''
	else:
		b1 += a1[j]
C = []
for i in A:
	if find1(i) == 1:
		C.append(i)
print(*C)


(m, n) = map(int, input().split())
l = list(map(int, input().split()))
s = list(map(int, input().split()))
t = []
for i in range(n):
	for j in range(m):
		if s[i] == l[j]:
			t.append(j)
t.sort()
for i in t:
	print(l[i], end=' ')
print()


(n, m) = map(int, input().split(' '))
l1 = list(map(int, input().split(' ')))
l2 = list(map(int, input().split(' ')))
l3 = []
for i in l2:
	if i in l1:
		l3.append(i)
for i in l1:
	if i in l3:
		print(i, end=' ')


(n, m) = map(int, input().split())
code = [int(i) for i in input().split()]
fingers = [int(i) for i in input().split()]
for i in code:
	if i in fingers:
		print(i, end=' ')


(n, k) = map(int, input().split())
a = input().split()
b = input().split()
for i in a:
	if i in b:
		print(i, end=' ')


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
d = set(map(int, input().split()))
ans = []
for el in arr:
	if el in d:
		ans.append(el)
print(' '.join(map(str, ans)))


a = [int(x) for x in input().split()]
b = [int(i) for i in input().split()]
c = [int(j) for j in input().split()]
d = len(b)
for i in range(d):
	if b[i] in c:
		print(b[i], end=' ')


(n, m) = [int(x) for x in input().split(' ')]
ns = [int(x) for x in input().split(' ')]
fp = [int(x) for x in input().split(' ')]
for i in range(len(ns)):
	if ns[i] in fp:
		print(ns[i], end=' ')


(n, m) = map(int, input().split())
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
ans = ''
for i in x:
	if i in y:
		if len(ans) == 0:
			ans += str(i)
		else:
			ans += ' ' + str(i)
print(ans)


(n, m) = input().split()
x = list(input().split())
y = list(input().split())
print(*filter(lambda x: x in y, x))


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
s = set(map(int, input().split()))
z = []
for q in range(n):
	if a[q] in s:
		z.append(a[q])
print(*z)


(x, y) = input().split()
l = input().split()
l2 = input().split()
for i in l:
	if i in l2:
		print(i, end=' ')


def main():
	(n, m) = list(map(int, input().split()))
	nums = list(map(int, input().split()))
	exists = list(map(int, input().split()))
	res = []
	for i in nums:
		if i in exists:
			res.append(str(i))
	print(' '.join(res))
main()


(n, m) = map(int, input().split())
seq = list(map(int, input().split()))
figpr = list(map(int, input().split()))
li = []
for i in seq:
	if i in figpr:
		li.append(i)
for i in li:
	print(i, end=' ')


def go():
	(n, m) = (int(i) for i in input().split(' '))
	a = [int(i) for i in input().split(' ')]
	b = [int(i) for i in input().split(' ')]
	c = []
	for i in b:
		try:
			c.append(a.index(i))
		except:
			continue
	return ' '.join((str(a[i]) for i in sorted(c)))
print(go())


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
s = set(l)
s1 = set(map(int, input().split()))
x = list(s & s1)
for i in range(n):
	if l[i] in x:
		print(l[i], end=' ')


input()
a = list(map(int, input().split()))
v = list(map(int, input().split()))
for i in a:
	if i in v:
		print(i, end=' ')


R = lambda : list(map(int, input().split()))
(n, a, b) = (R(), R(), R())
print(' '.join(map(str, (x for x in a if x in b))))


(n, m) = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]
res = []
for elem in c:
	if elem in d:
		res.append(elem)
print(*res)


(n, m) = map(int, input().split())
s = input()
ans = list()
numbers1 = list(map(int, s.split()))
b = input()
numbers2 = list(map(int, b.split()))
for x in range(0, len(numbers1), 1):
	if numbers1[x] in numbers2:
		ans.append(numbers1[x])
print(*ans)


inp = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
for item in x:
	if item in y:
		print(item, end=' ')


(n, m) = map(int, input().split())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
mk = [0] * 10
for i in a1:
	mk[i] += 1
for i in a2:
	mk[i] += 1
for i in range(len(a1)):
	if mk[a1[i]] == 2:
		print(a1[i], end=' ')


x = [int(i) for i in input().split()]
(n, m, res) = (x[0], x[1], [])
y = input().split()
z = input().split()
for i in y:
	if i in z:
		res.append(i)
print(' '.join(res))


fin = [0] * 12
I = input().split()
n = int(I[0])
m = int(I[1])
J = input().split()
I = input().split()
for i in range(0, m):
	fin[int(I[i])] = 1
for i in range(0, n):
	if fin[int(J[i])] == 1:
		print(J[i], end=' ')


(n, m) = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
inter = set(x) & set(y)
for i in x:
	if i in inter:
		print(i, end=' ')


import sys

def main():
	(n, m) = map(int, sys.stdin.readline().split())
	nl = list(map(int, sys.stdin.readline().split()))
	ml = list(map(int, sys.stdin.readline().split()))
	res = []
	for i in nl:
		if i in ml:
			res.append(str(i))
	print(' '.join(res))
main()


import sys
lines = sys.stdin.readlines()
sequence = lines[1].split()
finger = set(lines[2].split())
result = []
for key in sequence:
	if key in finger:
		result.append(key)
print(' '.join(result))


MIS = lambda : map(int, input().split())
(n, m) = MIS()
pw = list(MIS())
fprint = set(MIS())
for x in pw:
	if x in fprint:
		print(x, end=' ')


input()
s = list(map(int, input().split()))
z = list(map(int, input().split()))
for n in s:
	if n in z:
		print(n, end=' ')


(n, m) = list(map(int, input().split()))
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
for i in arr1:
	if i in arr2:
		print(i, end=' ')


(n, m) = map(int, input().split())
x = [int(p) for p in input().split()]
y = [int(q) for q in input().split()]
idx = []
for q in y:
	if q in x:
		idx.append(x.index(q))
idx.sort()
for i in idx:
	print(x[i], end=' ')


import sys
(n, m) = map(int, sys.stdin.readline().split())
x = [int(xx) for xx in input().split()]
y = [int(xx) for xx in input().split()]
if len([i for i in x if i in y]) == 0:
	print('\n')
else:
	ans = list()
	for i in range(len(x)):
		if x[i] in y:
			ans.append(x[i])
	for el in ans:
		print(el, end=' ')


(a, b) = map(int, input().split())
l = list(map(int, input().split()))
k = list(map(int, input().split()))
s = []
for i in l:
	for j in k:
		if i == j:
			s.append(i)
for i in s:
	print(i, end=' ')


(n, m) = map(int, input().split())
x = list(map(int, input().split()))
y = set(map(int, input().split()))
z = []
for i in range(n):
	if x[i] in y:
		z.append(x[i])
print(*z)


(n, m) = map(int, input().split())
posl = list(map(int, input().split()))
otp = list(map(int, input().split()))
ans = []
for i in otp:
	if i in posl:
		ans.append((posl.index(i), i))
ans.sort()
print(' '.join((str(n[1]) for n in ans)))


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l1 = list(map(int, input().split()))
d = dict.fromkeys(l1)
for i in l:
	if i in d:
		print(i, end=' ')


(n, m) = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]

def mergeSort(a):
	if len(a) <= 1:
		return a
	mid = len(a) // 2
	left = mergeSort(a[:mid])
	right = mergeSort(a[mid:])
	return merge(left, right)

def merge(left, right):
	result = []
	while len(left) > 0 and len(right) > 0:
		if left[0] <= right[0]:
			result.append(left[0])
			left = left[1:]
		else:
			result.append(right[0])
			right = right[1:]
	if len(left) > 0:
		result += left
	if len(right) > 0:
		result += right
	return result

def binarySearch(arr, s, b, e):
	if b > e:
		return False
	else:
		mid = (b + e) // 2
		if arr[mid] == s:
			return True
		elif arr[mid] < s:
			return binarySearch(arr, s, b + 1, e)
		else:
			return binarySearch(arr, s, b, e - 1)
y = mergeSort(y)
for i in range(0, n):
	if binarySearch(y, x[i], 0, len(y) - 1):
		print(x[i], end=' ')


def read_nums():
	return [int(x) for x in input().split()]
(n, m) = read_nums()
seq = read_nums()
fingers = read_nums()
res = []
for f in seq:
	if f in fingers:
		res.append(f)
res = [str(x) for x in res]
print(' '.join(res))


(n, m) = [int(v) for v in input().split()]
x = [int(v) for v in input().split()]
y = {int(v) for v in input().split()}
print(' '.join((str(v) for v in x if v in y)))


input_strs = lambda : input().split()
(n, m) = input_strs()
x = input_strs()
y = input_strs()
d = []
for i in range(len(x)):
	is_there = False
	for j in range(len(y)):
		if x[i] == y[j]:
			is_there = True
	if is_there:
		d.append(x[i])
output = ''
for i in range(len(d)):
	output += d[i] + ' '
print(output)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(0, n):
	for j in range(0, m):
		if a[i] == b[j]:
			print(a[i])


(n, m) = map(int, input().split())
seq = input().split()
pattern = input().split()
idx = []
for i in range(m):
	if pattern[i] in seq:
		idx.append((pattern[i], seq.index(pattern[i])))
if len(idx) == 0:
	print('\n')
	exit()
idx = sorted(idx, key=lambda x: x[1])
for i in range(len(idx)):
	print(idx[i][0], end=' ')


(n, m) = map(int, input().split(' '))
seq = list(map(int, input().split(' ')))
fin = list(map(int, input().split(' ')))
code = []
for i in seq:
	if i in fin:
		code.append(i)
for i in code:
	print(i, end=' ')


str1 = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
ans = []
for a in x:
	if a in y:
		ans.append(a)
print(' '.join(list(map(str, ans))))


(n, m) = map(int, input().split())
nl = list(map(int, input().split()))
ml = list(map(int, input().split()))
for i in nl:
	if i in ml:
		print(i, end=' ')


x = input()
x = x.split()
n = int(x[0])
m = int(x[1])
os = input()
os = os.split()
os = [int(i) for i in os]
fs = input()
fs = fs.split()
fs = [int(i) for i in fs]
for i in os:
	if i in fs:
		print(i, end=' ')


(a, b) = map(int, input().split())
A = list(map(int, input().split()))
B = set(map(int, input().split()))
to_print = []
for i in A:
	if i in B:
		to_print.append(str(i))
print(' '.join(to_print))


input()
x = input().split()
y = input().split()
print(' '.join((el for el in x if el in y)))


mat = []
num_dig_keys = input().split()
num_dig_keys = list(map(int, num_dig_keys))
if num_dig_keys[0] >= 1 and num_dig_keys[1] <= 10:
	if len(num_dig_keys) > 2:
		print('enter correctly the the number of digits in sequence and number of keys on the keypad having finger print')
		exit(0)
	sequence = input().split()
	sequence = list(map(int, sequence))
	for x in sequence:
		if x > 9:
			exit(0)
	if len(sequence) > num_dig_keys[0]:
		print('enter correctly the number of digits in the sequence')
		exit(0)
	fin_print = input().split()
	fin_print = list(map(int, fin_print))
	for x in sequence:
		if x > 9:
			exit(0)
	if len(sequence) > num_dig_keys[0]:
		print('enter correctly the number of digits having fingerprint')
		exit(0)
	for x in sequence:
		for y in fin_print:
			if y == x:
				mat.append(y)
	for z in mat:
		print(z, end=' ')


(n, m) = map(int, input().split())
x = [int(q) for q in input().split()]
y = [int(q) for q in input().split()]
ans = []
for i in range(len(x)):
	if x[i] in y:
		ans.append(x[i])
for item in ans:
	print(item, end=' ')


(n, m) = map(int, input().split()[:2])
a = list(map(int, input().split()[:n]))
b = list(map(int, input().split()[:m]))
l = []
for i in b:
	if i in a:
		l.append(a.index(i))
l.sort()
for i in l:
	print(a[i], end=' ')


(n, k) = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
for i in x:
	if i in y:
		print(i, end=' ')


import time

def guessCode(serial, fingerdigits):
	keyCode = []
	for x in serial:
		if x in fingerdigits:
			keyCode.append(x)
	return keyCode

def solve():
	(digits, fkeys) = [int(x) for x in input().split()]
	keycode = []
	serial = list(map(int, input().split()))
	fingerdigits = list(map(int, input().split()))
	keycode = guessCode(serial, fingerdigits)
	print(' '.join((str(x) for x in keycode)))
solve()


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
s = list(map(int, input().split()))
for i in a:
	if i in s:
		print(i, end=' ')


(n, m) = str(input()).split()
(n, m) = (int(n), int(m))
seq = str(input()).split()
seq = [int(i) for i in seq]
fp = str(input()).split()
fp = [int(i) for i in fp]
ftfp = [i for i in fp if i in seq]
res = ''
for i in seq:
	if i in ftfp:
		res += str(i) + ' '
print(res.rstrip())


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
lis = []
for i in range(len(a)):
	if a[i] in b:
		lis.append(a[i])
for i in range(len(lis)):
	print(lis[i], end=' ')


import sys
lines = sys.stdin.readlines()
(n, m) = lines[0].strip().split(' ')
keys_input = lines[1].strip().split(' ')
verified_keys = set(lines[2].strip().split(' '))
result = [key for key in keys_input if key in verified_keys]
print(' '.join(result))


(n, k) = input().split()
(n, k) = [int(n), int(k)]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = []
for i in range(0, len(a)):
	for j in range(0, len(b)):
		if a[i] == b[j]:
			c.append(a[i])
print(*c, sep=' ')


x = list(map(int, input().split(' ')))
y = list(map(int, input().split(' ')))
z = list(map(int, input().split(' ')))
print(*[i for i in y if i in z], end=' ')


a = [int(i) for i in input().split()]
n = a[0]
m = a[1]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
ans = []
for i in range(len(a)):
	if a[i] in b:
		ans.append(a[i])
if len(ans) == 0:
	print()
else:
	for i in ans:
		print(i, end=' ')
	print()


ch = input()
a = int(ch[0:ch.index(' ')])
b = int(ch[ch.index(' ') + 1:])
seq = input()
fp = input()
lseq = [int(seq[i]) for i in range(len(seq)) if seq[i] != ' ']
lfp = [int(fp[i]) for i in range(len(fp)) if fp[i] != ' ']
ch = ''
for i in range(len(lseq)):
	if lseq[i] in lfp:
		ch = ch + str(lseq[i]) + ' '
print(ch)


(m, n) = list(map(int, input().split()))
seq = list(map(int, input().split()))
keys = list(map(int, input().split()))
output = [s for s in seq if s in keys]
print(' '.join((str(o) for o in output)))


(n, m) = [int(x) for x in input().split()]
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for i in range(0, n):
	for j in range(0, m):
		if a[i] == b[j]:
			c.append(a[i])
for k in range(0, len(c)):
	print(c[k], end=' ')


(n, m) = map(int, input().split())
xs = list(map(int, input().split()))
ys = set(map(int, input().split()))
for i in xs:
	if i in ys:
		print(i, end=' ')


(n, m) = map(int, input().split())
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
k = []
for i in range(m):
	for j in range(n):
		if y[i] == x[j]:
			k.append(j)
n = 1
while n < len(k):
	for i in range(len(k) - n):
		if k[i] > k[i + 1]:
			(k[i], k[i + 1]) = (k[i + 1], k[i])
	n += 1
for i in range(len(k)):
	print(x[k[i]], end=' ')


def binarySearch(arr, l, r, x):
	if r >= l:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			return binarySearch(arr, l, mid - 1, x)
		else:
			return binarySearch(arr, mid + 1, r, x)
	else:
		return -1
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b.sort()
for i in a:
	if binarySearch(b, 0, k - 1, i) != -1:
		print(i, end=' ')


(a, b) = map(int, input().split())
c = list(map(int, input().split()))
d = list(map(int, input().split()))
t = []
p = 0
l = 0
z = []
j = 0
for i in range(a):
	t.append(c[p])
	p = p + 1
for ir in range(b):
	z.append(d[l])
	l = l + 1
for il in range(len(t)):
	if t[j] in z:
		print(t[j], end=' ')
	j = j + 1


input()
R = lambda : map(int, input().split())
a = list(R())
b = set(R())
print(' '.join((str(i) for i in a if i in b)))


(n, m) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
s = 0
for i in a:
	for j in b:
		if i == j:
			print(i, end=' ')


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = []
for ch in a:
	if ch in b:
		s.append(str(ch))
print(' '.join(s))


import sys
import math
fileoperation = 0
if fileoperation:
	orig_stdout = sys.stdout
	orig_stdin = sys.stdin
	inputfile = open('W:/Competitive Programming/input.txt', 'r')
	outputfile = open('W:/Competitive Programming/output.txt', 'w')
	sys.stdin = inputfile
	sys.stdout = outputfile
mod = 1000000007

def nospace(l):
	ans = ''.join((str(i) for i in l))
	return ans
(n, m) = map(int, sys.stdin.readline().split(' '))
a = list(map(int, sys.stdin.readline().split(' ')))
b = list(map(int, sys.stdin.readline().split(' ')))
ans = []
for aa in a:
	if aa in b:
		ans.append(aa)
print(*ans)
if fileoperation:
	sys.stdout = orig_stdout
	sys.stdin = orig_stdin
	inputfile.close()
	outputfile.close()


(n, m) = map(int, input().split())
x = input().split()
y = input().split()
x = [e for e in x if e in y]
print(' '.join(x))


(n, m) = map(int, input().split())
xs = list(map(int, input().split()))
ys = list(map(int, input().split()))
ps = [False] * len(ys)
res = []
for x in xs:
	try:
		idx = ys.index(x)
		if not ps[idx]:
			ps[idx] = True
			res.append(x)
	except ValueError:
		pass
print(*res, sep=' ')


(n, m) = [int(i) for i in input().split()]
x = [int(j) for j in input().split()]
y = [int(k) for k in input().split()]
for a in range(len(x)):
	if x[a] in y:
		print(x[a], end=' ')


(n, m) = list(map(int, input().split()))
d = list(map(int, input().split()))
s = set(map(int, input().split()))
for i in d:
	if i in s:
		print(i, end=' ')


import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *

class Scanner:

	@staticmethod
	def int():
		return int(sys.stdin.readline().rstrip())

	@staticmethod
	def string():
		return sys.stdin.readline().rstrip()

	@staticmethod
	def map_int():
		return [int(x) for x in Scanner.string().split()]

	@staticmethod
	def string_list(n):
		return [input() for i in range(n)]

	@staticmethod
	def int_list_list(n):
		return [Scanner.map_int() for i in range(n)]

	@staticmethod
	def int_cols_list(n):
		return [int(input()) for i in range(n)]

class Math:

	@staticmethod
	def gcd(a, b):
		if b == 0:
			return a
		return Math.gcd(b, a % b)

	@staticmethod
	def lcm(a, b):
		return a * b // Math.gcd(a, b)

	@staticmethod
	def divisor(n):
		res = []
		i = 1
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				res.append(i)
				if i != n // i:
					res.append(n // i)
		return res

	@staticmethod
	def round_up(a, b):
		return -(-a // b)

	@staticmethod
	def is_prime(n):
		if n < 2:
			return False
		if n == 2:
			return True
		if n % 2 == 0:
			return False
		d = int(n ** 0.5) + 1
		for i in range(3, d + 1, 2):
			if n % i == 0:
				return False
		return True

def pop_count(x):
	x = x - (x >> 1 & 6148914691236517205)
	x = (x & 3689348814741910323) + (x >> 2 & 3689348814741910323)
	x = x + (x >> 4) & 1085102592571150095
	x = x + (x >> 8)
	x = x + (x >> 16)
	x = x + (x >> 32)
	return x & 127
MOD = int(1000000000.0) + 7
INF = int(1000000000000000.0)

def solve():
	(N, M) = Scanner.map_int()
	X = Scanner.map_int()
	Y = {y for y in Scanner.map_int()}
	ans = []
	for x in X:
		if x in Y:
			ans.append(x)
	print(*ans)

def main():
	solve()
main()


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
f = set(map(int, input().split()))
c = set(a) & f
a = [ai for ai in a if ai in c]
print(*a)


(n, m) = [int(i) for i in input().split()]
nx = [int(i) for i in input().split()]
my = [int(i) for i in input().split()]
a = []
for i in range(m):
	if nx.count(my[i]) != 0:
		a.append(nx.index(my[i]))
a.sort()
for i in a:
	print(nx[i], end=' ')


(n, m) = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
l = ' '
for i in x:
	if i in y:
		l += str(i) + ' '
	i += 1
print(l)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def LS():
	return sys.stdin.readline().split()

def S():
	return input()

def main():
	(n, m) = LI()
	l1 = LI()
	l2 = LI()
	a = []
	for x in l2:
		if l1.count(x) > 0:
			a.append([x, l1.index(x)])
	a = sorted(a, key=lambda x: x[1])
	ans = []
	for x in a:
		ans.append(x[0])
	return ' '.join([str(x) for x in ans])
print(main())


excess = input()
first = [int(x) for x in input().split()]
second = [int(x) for x in input().split()]
answer = [str(x) for x in first if x in second]
print(' '.join(answer))


(n, m) = map(int, input().split())
l = list(map(int, input().strip().split()))
k = list(map(int, input().strip().split()))
for j in range(n):
	if l[j] in k:
		print(l[j], end=' ')


(n, m) = list(map(int, input().split()))
s = list(map(int, input().split()))
keys = list(map(int, input().split()))
ans = ''
for d in s:
	if d in keys:
		ans += str(d) + ' '
print(ans)


input()
(X, Y) = (list(map(int, input().split())), set(map(int, input().split())))
print(*filter(lambda x: x in Y, X))


n = input().split(' ')
line_one = []
line_two = []
res = []
line_one = input().split(' ')
line_two = input().split(' ')
for i in range(int(n[0])):
	for j in range(int(n[1])):
		if line_one[i] == line_two[j]:
			res.append(line_one[i])
for i in res:
	print(i, end=' ')


(n, m) = map(int, input().split())
ar = list(map(int, input().split()))
br = list(map(int, input().split()))
ans = []
for x in ar:
	if x in br:
		ans.append(x)
print(*ans)


from collections import deque
from sys import stdin
lines = deque((line.strip() for line in stdin.readlines()))

def nextline():
	return lines.popleft()

def types(cast, sep=None):
	return tuple((cast(x) for x in strs(sep=sep)))

def ints(sep=None):
	return types(int, sep=sep)

def strs(sep=None):
	return tuple(nextline()) if sep == '' else tuple(nextline().split(sep=sep))

def main():
	nextline()
	nums = strs()
	f = set(strs())
	print(' '.join((n for n in nums if n in f)))
main()


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in a:
	if b.count(i) >= 1:
		print(i, end=' ')


import sys
import math
import bisect

def main():
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = []
	for a in A:
		if a in B:
			C.append(a)
	print(' '.join(list((str(a) for a in C))))
main()


(n, m) = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
a = [-1] * 10
b = []
for i in range(m):
	if y[i] in x:
		a[x.index(y[i])] = y[i]
for i in range(len(a)):
	if a[i] != -1:
		b.append(a[i])
print(*b)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
r = []
for i in range(n):
	if a[i] in b:
		r.append(a[i])
print(*r, sep=' ')


(n, m) = map(int, input().split())
l1 = []
l2 = []
d1 = {}
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
for i in range(len(l2)):
	for j in range(len(l1)):
		if l1[j] == l2[i]:
			d1[j] = l2[i]
for i in range(n):
	if i in d1.keys():
		print(d1[i], end=' ')


(n, m) = map(int, input().split())
keys = list(map(int, input().split()))
fingerprints = list(map(int, input().split()))
for i in keys:
	if i in fingerprints:
		print(i, end=' ')
print()


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = set(map(int, input().split()))
print(*filter(b.__contains__, a))


(n, m) = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]
for i in range(n):
	if a[i] in b:
		print(a[i], end=' ')


(n, m) = [int(i) for i in input().split()]
x = list(map(int, input().split()))
y = list(map(int, input().split()))
res = [i for i in x if i in y]
print(*res)


(n, m) = map(int, input().split())
dict1 = {}
arr = list(map(int, input().split()))
arr1 = list(map(int, input().split()))
ansarr = []
for i in arr:
	if i in arr1:
		ansarr.append(i)
print(*ansarr)


(n, m) = input().split()
n = int(n)
m = int(m)
list1 = [int(x) for x in input().split()]
list2 = [int(x) for x in input().split()]
for i in list1:
	if i in list2:
		print(i, end=' ')


l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
l = []
for i in l2:
	if i in l3:
		l.append(i)
print(*l, sep=' ')


def main():
	(n, m) = [int(t) for t in input().split()]
	s = [int(t) for t in input().split()]
	f = [int(t) for t in input().split()]
	result = []
	for item in f:
		if item in s:
			result.append(s.index(item))
	result.sort()
	for item in result:
		print(s[item], end=' ')
	print()
main()


(n, m) = map(int, input().split())
l1 = [int(x) for x in input().split()]
l2 = [int(x) for x in input().split()]
s = ''
for i in range(n):
	if l1[i] in l2:
		s += str(l1[i]) + ' '
print(s)


(a, b) = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
sm = []
for i in range(a):
	for l in range(b):
		if x[i] == y[l]:
			sm.append(x[i])
print(*sm, sep=' ')


nm = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
result = []
for i in range(nm[0]):
	if x[i] in y:
		result.append(x[i])
print(*result)


s = input().split()
n = int(s[0])
m = int(s[1])
nn = input().split()
mm = input().split()
ans = []
for i in range(0, n):
	for j in range(0, m):
		if nn[i] == mm[j]:
			ans.append(int(mm[j]))
ans = str(ans)
ans = ans.replace('[', '')
ans = ans.replace(']', '')
ans = ans.replace(',', '')
print(ans)


input()
l = list(map(str, input().split()))
f = list(map(str, input().split()))
ans = []
for i in l:
	if i in f:
		ans.append(i)
	if len(ans) == len(f):
		break
print(' '.join(ans), end='')


(N, M) = list(map(int, input().split()))
X = [int(x) for x in input().split()]
Y = [int(x) for x in input().split()]
print(*[x for x in X if x in Y])


from collections import defaultdict as dd
(n, m) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
final = []
d = dd(int)
for i in b:
	d[i] = 1
for i in a:
	if d[i] == 1:
		final.append(i)
print(*final)


s1 = input()
arr1 = input()
arr2 = input()
(arr1, arr2) = (list(map(int, arr1.split())), list(map(int, arr2.split())))
ans = []
for i in arr1:
	if i in arr2:
		ans.append(i)
ans = ' '.join(map(str, ans))
print(ans)


a = input()
b = [i for i in input().split()]
c = [i for i in input().split()]
for i in b:
	if i not in c:
		continue
	for j in c:
		if j == i:
			print(j, end=' ')
			break


import sys
import collections
import itertools as it

def readArray(type=int):
	line = input()
	return [type(x) for x in line.split()]

def solve():
	(n, m) = readArray()
	seq = readArray()
	fprints = readArray()
	cc = 0
	freq = collections.defaultdict(int)
	for x in fprints:
		freq[x] += 1
	for x in seq:
		freq[x] += 1
		if freq[x] > 1:
			print(x, end=' ')
	print()
solve()


R = lambda : list(map(int, input().split()))
(n, a, b) = (R(), R(), R())
print(*(x for x in a if x in b), sep=' ')


(a, b) = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]
for i in c:
	if i in d:
		print(i, end=' ')


q = input()
(n, m) = q.split()
n = int(n)
m = int(m)
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
for i in range(n):
	if a[i] in b:
		print(a[i], end=' ')


(n, m) = map(int, input().split())
x = [int(x) for x in input().split()]
y = [int(y) for y in input().split()]
for i in x:
	if i in y:
		print(str(i), end=' ')


import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
sys.setrecursionlimit(10000)

def read_int():
	return int(input())

def read_int_n():
	return list(map(int, input().split()))

def read_float():
	return float(input())

def read_float_n():
	return list(map(float, input().split()))

def read_str():
	return input()

def read_str_n():
	return list(map(str, input().split()))

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

@mt
def slv(N, M, X, Y):
	ans = X[:]
	for x in X:
		if x not in Y:
			ans.remove(x)
	return ' '.join(map(str, ans))

def main():
	(N, M) = read_int_n()
	X = read_int_n()
	Y = read_int_n()
	print(slv(N, M, X, Y))
main()


import sys
(n, m) = map(int, sys.stdin.readline().split())
x = list(map(int, sys.stdin.readline().split()))
y = list(map(int, sys.stdin.readline().split()))
ans = []
for i in x:
	if i in y:
		ans.append(i)
print(' '.join(map(str, ans)))


x = input().split()
a = int(x[0])
b = int(x[1])
s1 = ''.join(input().split(' '))
s2 = ''.join(input().split(' '))
ans = []
for c in s1:
	if c in s2:
		ans.append(c)
print(' '.join(ans))


from sys import stdin, stdout
nm = list(map(int, stdin.readline().strip().split()))
n = nm[0]
m = nm[1]
n_list = list(map(int, stdin.readline().strip().split()))
m_list = list(map(int, stdin.readline().split()))
res_list = []
for x in n_list:
	if x in m_list:
		res_list.append(str(x))
stdout.write(' '.join(res_list))


(n, m) = [int(x) for x in input().split()]
s1 = [x for x in input().split()]
s2 = [x for x in input().split()]
for item in s1:
	if item in s2:
		print(item, end=' ')


(n, m) = [int(x) for x in input().split()]
x = [int(x) for x in input().split()]
y = [int(x) for x in input().split()]
ans = []
for e in x:
	if e in y:
		ans.append(str(e))
print(' '.join(ans))


c = input()
n = int(list(c.split())[0])
m = int(list(c.split())[1])
seq = list(input().split())
fprnt = list(input().split())
x = list(filter(lambda seq: seq in fprnt, seq))
for i in range(len(x)):
	print(x[i], end=' ')


(s, f) = map(int, input().split())
a = list(map(int, input().split()))
l = list(map(int, input().split()))
z = []
for i in range(s):
	for j in range(f):
		if a[i] == l[j]:
			z.append(a[i])
print(*z)


a = list(map(int, input().split()))
t = list(map(int, input().split()))
y = list(map(int, input().split()))
a = []
u = []
for i in range(len(y)):
	if y[i] in t:
		u.append(y[i])
for j in range(len(u)):
	a.append([t.index(u[j]), u[j]])
a.sort()
for k in a:
	print(k[1], end=' ')


(n, m) = map(int, input().split())
x = input().split()
y = input().split()
p = ''
for i in range(n):
	for j in range(m):
		if x[i] == y[j]:
			p += x[i] + ' '
print(p)


num = [int(a) for a in input('').split()]
nse = num[0]
nfin = num[1]
se = [int(b) for b in input('').split()]
fin = [int(c) for c in input('').split()]
for i in range(0, nse):
	if se[i] in fin:
		print(se[i], end=' ')
print('')


(a, b) = map(int, input().split())
c = list(map(int, input().split()))
d = list(map(int, input().split()))
for i in range(a):
	for j in range(b):
		if c[i] == d[j]:
			print(c[i], end=' ')
		else:
			print(end='')


(n, m) = map(int, input().split())
x = list(map(int, input().split()))
y = set(map(int, input().split()))
for i in x:
	if i in y:
		print(i, end=' ')
print()


def main():
	(n, m) = [int(i) for i in input().split(' ')]
	x = input().split(' ')
	y = input().split(' ')
	ans = [None] * 10
	for i in y:
		if i in x:
			ans[x.index(i)] = i
	ans = [i for i in ans if i is not None]
	print(' '.join(ans))
main()


n = input().split()
subseq = input().split()
fingerprint = input().split()
counter = 0
for i in range(int(n[0])):
	if subseq[i] in fingerprint:
		if counter == 0:
			print(subseq[i], end='')
			counter = 1
		else:
			print('', subseq[i], end='')


def fingerprints():
	(n, m) = map(int, input().split(sep=' '))
	numbers = list(map(int, input().split(sep=' ')))
	f = list(map(int, input().split(sep=' ')))
	for i in numbers:
		if i in f:
			print(i, end=' ')
fingerprints()


input()
(X, Y) = (input().split(), input().split())
print(*filter(lambda x: x in Y, X))


(n, m) = map(int, input().split())
sequence = list(map(int, input().split()))
fingerprints = list(map(int, input().split()))
code = []
for i in sequence:
	if i in fingerprints:
		code.append(i)
print(' '.join(map(str, code)))


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
arr1 = list(map(int, input().split()))
s = set()
for elem in arr1:
	s.add(elem)
for elem in arr:
	if elem in s:
		print(elem, end=' ')


(d, e) = map(int, input().split())
l = [int(x) for x in input().split()]
y = [int(x) for x in input().split()]
b = []
for i in l:
	if i in y:
		b.append(str(i))
print(' '.join(b))


(n, m) = map(int, input().split())
a = [i for i in map(int, input().split())]
b = [i for i in map(int, input().split())]
c = list(set(a) & set(b))
d = []
for i in c:
	d.append(a.index(i))
z = [x for (_, x) in sorted(zip(d, c))]
print(*z, sep=' ')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = []
for i in b:
	try:
		ans.append(a.index(i))
	except:
		continue
ans.sort()
for item in ans:
	print(a[item], end=' ')


input().split(' ')
l1 = [int(i) for i in input().split(' ')]
l2 = [int(j) for j in input().split(' ')]
out = []
for a in l1:
	for b in l2:
		if a == b:
			out.append(a)
		else:
			continue
for x in out:
	print(x, end=' ')


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = []
for i in b:
	if i in a:
		s.append(a.index(i))
s.sort()
for i in range(len(s)):
	s[i] = a[s[i]]
print(*s)


input()
x = [int(a) for a in input().split()]
y = [int(a) for a in input().split()]
z = [str(i) for i in x if i in y]
print(' '.join(z))


(x, y) = input().split()
lst1 = list(map(int, input().split()))
lst2 = list(map(int, input().split()))
for i in lst1:
	for t in lst2:
		if i == t:
			print(i, end=' ')


import sys
(n, m) = map(int, input().split())
s = list(map(int, input().split()))
fin = list(map(int, input().split()))
for i in s:
	if i in fin:
		print(i, end=' ')


m = input()
s = map(int, input().split())
t = str(input()).count
for _ in s:
	if t(str(_)):
		print(_, end=' ')


input()
d = [int(x) for x in input().split()]
c = set([int(x) for x in input().split()])
r = ''
for i in d:
	if i in c:
		r += str(i) + ' '
if len(r) != 1:
	print(r[:-1])


(n, m) = map(int, input().split())
seq = list(map(int, input().split()))
finger = list(map(int, input().split()))
print(' '.join(map(str, filter(lambda a: a in finger, seq))))


(n, m) = map(int, input().split())
keys = list(map(int, input().split()))
fing = list(map(int, input().split()))

def intersection(lst1, lst2):
	lst3 = [value for value in lst1 if value in lst2]
	return lst3
f = intersection(keys, fing)
for x in f:
	print(x, end=' ')


(a, b) = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
for i in range(a):
	if b[i] in c:
		print(b[i], end=' ')
		c.remove(b[i])


(a, b) = map(int, input().split())
s1 = list(map(int, input().split()))
s2 = list(map(int, input().split()))
for i in range(0, a):
	if s1[i] in s2:
		print(s1[i], end=' ')


(n, m) = map(int, input().split())
toCheck = [int(x) for x in input().split()]
pres = set([int(x) for x in input().split()])
ans = []
for y in toCheck:
	if y in pres:
		ans.append(y)
print(*ans, sep=' ')


input()
fps = list(map(int, input().split(' ')))
keys = list(map(int, input().split(' ')))
fps = filter(lambda x: x in keys, fps)
print(' '.join((str(x) for x in fps)))


(n, m) = map(int, input().split())
code = map(int, input().split())
fingerprints = set(map(int, input().split()))
for i in code:
	if i in fingerprints:
		print(i, end=' ')


(a, b) = map(int, input().split())
c = list(map(int, input().split()))
d = list(map(int, input().split()))
e = []
for i in c:
	if i in d:
		e.append(i)
print(*e)


(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
o = []
for i in range(m):
	for u in range(n):
		if a[u] == b[i]:
			o.append([u, b[i]])
o.sort()
for ty in range(len(o)):
	print(o[ty][1], end=' ')


from sys import stdin
n = int(stdin.readline().rstrip().split()[0])
numbers = stdin.readline().rstrip().split()
fingers = stdin.readline().rstrip().split()
for d in numbers:
	if d in fingers:
		print(d, end=' ')


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(set(a).intersection(b))
index = []
for i in c:
	index.append(a.index(i))
index.sort()
new = []
for i in index:
	new.append(a[i])
print(*new)


import sys

def solve():
	(n, m) = sys.stdin.readline().strip().split()
	n = int(n)
	m = int(m)
	s1 = sys.stdin.readline().strip().split()
	s2 = sys.stdin.readline().strip().split()
	ans = []
	for i in range(len(s1)):
		if s1[i] in s2:
			ans.append(s1[i])
	if len(ans) == 0:
		print()
	else:
		for i in range(len(ans) - 1):
			print(ans[i], end=' ')
		print(ans[len(ans) - 1])
solve()


result = []
(n, m) = map(int, input().split())
seq = list(map(int, input().split()))
dic_fin = {}.fromkeys(map(int, input().split()))
for i in range(n):
	if seq[i] in dic_fin:
		result.append(seq[i])
print(*result)


(n, m) = [int(x) for x in input().split()]
s = input()
t = input()
for i in s:
	if i in t:
		print(i, end='')
print()


(n, m) = map(int, input().split())
lis = list(map(int, input().split()))
fin = list(map(int, input().split()))
for i in lis:
	if i in fin:
		print(i, end=' ')


(n, m) = tuple(map(int, input().split(' ')))[:2]
s1 = tuple(map(int, input().split(' ')))[:n]
s2 = tuple(map(int, input().split(' ')))[:m]
s = []
for i in s1:
	if i in s2:
		s.append(i)
strok = ''
for i in s:
	strok += str(i) + ' '
print(strok)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
x = list(map(int, input().split()))
a = [0] * 20
z = []
for i in l:
	a[i] += 1
for i in x:
	if a[i] == 1:
		z.append(l.index(i))
z.sort()
for i in z:
	print(l[i], end=' ')


(n, m) = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
lisofi = []
for i in x:
	if i in y:
		lisofi.append(i)
print(*lisofi, sep=' ')


(n, m) = [int(x) for x in input().split()]
x_i = [int(x) for x in input().split()]
y_i = [int(x) for x in input().split()]
output = ''
for i in x_i:
	for ii in y_i:
		if ii == i:
			output = output + str(i) + ' '
print(output)


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))
ans = []
for a in arr:
	if a in brr:
		ans.append(a)
for an in ans:
	print(an, end=' ')


from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from collections import defaultdict
import math
cin = stdin.readline

def cout(x):
	stdout.write(str(x) + '\n')

def nexint():
	return int(stdin.readline())

def readline():
	return map(int, stdin.readline().split())

def readlist():
	return list(map(int, stdin.readline().split()))

def sorted_indexes(arr):
	return sorted(range(len(arr)), key=arr.__getitem__)

def printr(arr):
	[stdout.write(str(x) + ' ') for x in arr]
	cout('')

def find_lt(a, x):
	i = bisect_left(a, x)
	if i:
		return a[i - 1]
	raise ValueError

def find_gt(a, x):
	i = bisect_right(a, x)
	if i != len(a):
		return a[i]
	raise ValueError
(n, m) = readline()
arr = readlist()
mp = readlist()
for i in arr:
	if i in mp:
		print(i, end=' ')


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
d = list(map(int, input().split()))
x = []
for i in l:
	if i in d:
		x.append(i)
print(*x)


l = input().split()
(n, m) = map(int, l)
x = input().split()
y = input().split()
ans = ''
k = False
for i in x:
	if i in y:
		ans += i + ' '
		k = True
if k == True:
	print(ans.strip())
else:
	print('')


(a, b) = map(int, input().split())
q = list(map(int, input().split()))
w = list(map(int, input().split()))
c = 0
for i in q:
	if i in w:
		print(i, end=' ')
		c += 1
if c == 0:
	print()


(n, m) = list(map(int, input().split()))
ol = list(map(int, input().split()))
fl = list(map(int, input().split()))
for i in ol:
	if i in fl:
		print(i, end=' ')


(n, m) = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
k = [0] * 10
for i in y:
	k[i] = 1
b = []
for i in x:
	if k[i]:
		b.append(i)
print(*b)


(n, m) = [int(x) for x in input().split()]
s = [int(x) for x in input().split()]
k = [int(x) for x in input().split()]
ans = []
for x in s:
	if x in k:
		ans.append(x)
print(' '.join(map(str, ans)))


(n, m) = map(int, input().split())
ln = list(map(int, input().split()))
lm = list(map(int, input().split()))
l = []
for i in ln:
	if i in lm:
		l.append(i)
for i in l:
	print(i, end=' ')
print()


read = lambda : map(int, input().split())
(n, m) = read()
x = list(read())
y = list(read())
ans = []
for d in x:
	if d in y:
		ans.append(d)
print(*ans)


(n, n) = map(int, input().split())
an = list(map(int, input().split()))
am = list(map(int, input().split()))
for i in an:
	if i in am:
		print(i, end=' ')


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 998244353
dd = [(0, -1), (1, 0), (0, 1), (-1, 0)]
ddn = [(0, -1), (1, -1), (1, 0), (1, 1), (0, 1), (-1, -1), (-1, 0), (-1, 1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	(n, m) = LI()
	a = LI()
	b = set(LI())
	r = []
	for c in a:
		if c in b:
			r.append(c)
			b.remove(c)
	return ' '.join(map(str, r))
print(main())


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
finger = list(map(int, input().split()))
ans = []
for i in arr:
	if i in finger:
		ans.append(i)
	else:
		continue
if len(ans) == 0:
	print('')
else:
	print(*ans, sep=' ')


info = [int(i) for i in input().split()]
numbers = [int(i) for i in input().split()]
kWp = [int(i) for i in input().split()]
code = list()
for i in range(info[0]):
	for k in range(info[1]):
		if numbers[i] == kWp[k]:
			code.append(kWp[k])
for i in range(len(code)):
	print(str(code[i]))


(n, m) = input().split()
n = int(n)
m = int(m)
l = input().split()
l = [int(i) for i in l]
k = input().split()
k = [int(i) for i in k]
s = set(k)
for i in l:
	if i in s:
		print(i, end=' ')


input()
a = input().split()
b = input().split()
c = []
for i in a:
	if i in b:
		c.append(i)
print(*c)


(n, m) = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
ans = []
for i in range(len(x)):
	if x[i] in y:
		ans.append(x[i])
if len(ans) == 0:
	print()
else:
	print(' '.join((str(i) for i in ans)))


def main():
	input()
	sequence = [int(x) for x in input().split()]
	fingerprints = [int(x) for x in input().split()]
	result = [str(x) for x in sequence if x in fingerprints]
	print(' '.join(result))
main()


(n, m) = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
ls = [0 for i in range(10)]
for i in range(m):
	ls[y[i]] = 1
for i in range(n):
	if ls[x[i]]:
		print(x[i], end=' ')


input()
n = list(map(int, input().split()))
m = list(map(int, input().split()))
a = set(m).intersection(set(n))
b = [x for x in n if x in a]
print(' '.join(map(str, b)))


(n, m) = map(int, input().split())
li = [int(x) for x in input().split(' ')]
fin = [int(x) for x in input().split(' ')]
ans = []
for i in li:
	if i in fin:
		ans.append(i)
for i in ans:
	print(i, end=' ')


(n, m) = map(int, input().split())
s = input().split()
f = input().split()
g = set(s)
f = set(f)
b = list(g & f)
for i in s:
	if i in b:
		print(i, end=' ')


(n, m) = map(int, input().split())
xi = list(map(int, input().split()))
yi = list(map(int, input().split()))
ans = []
for i in xi:
	if i in yi:
		print(i, end=' ')


import sys

def solution():
	line = input()
	n = int(line.split()[0])
	m = int(line.split()[1])
	seq = list(map(int, input().split()))
	fp = list(map(int, input().split()))
	result = []
	for el in seq:
		if el in fp:
			result.append(el)
	print(*result, sep=' ')
solution()


(n, m) = [int(n) for n in input().split()]
x = list()
y = list()
ans = list()
x = x + [int(x) for x in input().split()]
y = y + [int(y) for y in input().split()]
for i in x:
	for j in y:
		if i == j:
			ans = ans + [i]
for i in ans:
	print(i, end=' ')


(arr_len, prints_nr) = (int(x) for x in input().split())
arr = [int(x) for x in input().split()]
prints = set((int(x) for x in input().split()))
for elem in arr:
	if elem in prints:
		print(elem, end=' ')


import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
sys.setrecursionlimit(4100000)
INF = 1 << 60
MOD = 10 ** 9 + 7
(n, m) = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
for i in x:
	if i in y:
		print('%d ' % i, end='')


(n, m) = list(map(int, input().split()))
ans = []
x = list(map(int, input().split()))
y = list(map(int, input().split()))
for j in range(n):
	if x[j] in y:
		ans.append(x[j])
print(*ans)


def solve(s, f):
	ans = list()
	f_pool = set(f)
	for c in reversed(s):
		if not f_pool:
			break
		elif c in f_pool:
			ans.append(c)
			f_pool.remove(c)
	return ' '.join(reversed(list(map(str, ans))))

def main():
	(n, m) = list(map(int, input().split()))
	s = list(map(int, input().split()))
	f = list(map(int, input().split()))
	print(solve(s, f))
main()


from math import *
a = input()
b = input().split()
c = input()
ans = ''
for i in b:
	if i in c:
		ans += i + ' '
print(ans[:-1])


(n, m) = map(int, input().split())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l = [i for i in l1 if i in l2]
print(*l)


(n, m) = [int(x) for x in input().split()]
seq = []
fin = []
for x in input().split():
	seq.append(int(x))
for x in input().split():
	fin.append(int(x))
res = []
for x in seq:
	for y in fin:
		if x == y:
			res.append(x)
for x in res:
	print(x, end=' ')


(n, m) = map(int, input().split())
finger = [False] * 10
seq = map(int, input().split())
for d in map(int, input().split()):
	finger[d] = True
print(' '.join(map(str, filter(lambda x: finger[x], seq))))


(a, b) = map(int, input().split())
l = list(map(int, input().split()))
k = list(map(int, input().split()))
a = []
for i in k:
	if i in l:
		a.append(l.index(i))
a.sort()
k.clear()
for i in a:
	k.append(l[i])
for i in k:
	print(i, end=' ')


(n, m) = list(map(int, input().split()))
l = list(map(int, input().split()))
a = list(map(int, input().split()))
cnt = []
for i in range(m):
	ans = 0
	if a[i] in l:
		for j in range(l.index(a[i]), n):
			if l[j] in a:
				ans += 1
	cnt.append(ans)
if max(cnt) == 0:
	print()
	exit()
for i in range(l.index(a[cnt.index(max(cnt))]), n):
	if l[i] in a:
		print(l[i], end=' ')


import os, sys
(n, m) = list(map(int, input().split()))
N = list(input().split())
M = list(input().split())
op = ''
for i in range(n):
	for j in range(m):
		if N[i] == M[j]:
			op += N[i]
			continue
print(' '.join(list(op)))


xy = [int(x) for x in input().split()]
map = {}
a = input().split()
for x in a:
	map[x] = 0
b = input().split()
for x in b:
	map[x] = 1
s = ''
for o in a:
	if map[o] == 1:
		if s == '':
			s = o
		else:
			s = s + ' ' + str(o)
print(s)


R = lambda : map(int, input().split())
(a, b, c) = (R(), R(), set(R()))
print(*[x for x in b if x in c])


(n, m) = map(int, input().split(' '))
x = map(int, input().split(' '))
y = list(map(int, input().split(' ')))
ans = [e for e in x if e in y]
for e in ans:
	print(e, end=' ')


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
arr1 = set(list(map(int, input().split())))
ans = []
for i in arr:
	if i in arr1:
		ans.append(i)
for i in ans:
	print(i, end=' ')


(N, M) = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
ans = ''
for x in X:
	if x in Y:
		if 0 < len(ans):
			ans += ' '
		ans += str(x)
print(ans)


t = list(map(int, input().split(' ')))
l1 = list(map(int, input().split(' ')))
l2 = list(map(int, input().split(' ')))
l3 = []
for i in l1:
	if i in l2:
		l3.append(i)
for i in l3:
	print(i, end=' ')


(p, f) = map(int, input().split())
pos = list(map(int, input().split()))
fin = list(map(int, input().split()))
flag = 0
for elem in pos:
	if elem in fin:
		print(elem, end=' ')
		flag = 1
if flag == 0:
	print(' ')


(m, n) = map(int, input().split())
Known = list(map(int, input().split()))
Check = list(map(int, input().split()))
strAnsw = ''
for i in range(m):
	if Known[i] in Check:
		strAnsw = strAnsw + str(Known[i]) + ' '
print(strAnsw)


(n, m) = map(int, input().split())
a = []
b = []
c = []
a += map(int, input().split())
b += map(int, input().split())
for i in a:
	if i in b and i not in c:
		print(i, end=' ')
		c.append(i)


(n, m) = map(int, input().split())
iz = [int(x) for x in input().split()]
otp = [int(x) for x in input().split()]
a = []
b = []
for i in otp:
	if i in iz:
		a.append(iz.index(i))
a.sort()
for i in a:
	print(iz[i], end=' ')


(a, b) = map(int, input().split())
s = [int(x) for x in input().split()]
q = [int(x) for x in input().split()]
for i in s:
	if i in q:
		print(i, end=' ')


some_chars = input()
chars = some_chars.split()
buttons = int(chars[0])
marked_buttons = int(chars[1])
clean_list = [' '] * buttons
marked_list = [' '] * marked_buttons
ans = [' '] * buttons
flag = 1
clean_list_str = input()
marked_list_str = input()
clean_list = clean_list_str.split()
marked_list = marked_list_str.split()
i = 0
for a in range(buttons):
	for b in range(marked_buttons):
		if clean_list[a] == marked_list[b]:
			if flag == 1:
				ans[i] = clean_list[a]
				i += 1
				flag = 0
			else:
				ans[i] = clean_list[a]
				i += 1
ans_str = ' '.join(ans)
print(ans_str)


(n, m) = map(int, input().split(' '))
known_sequence = list(map(int, input().split(' ')))
fingerprint_buttons = set(map(int, input().split(' ')))
intersect = set(known_sequence) & fingerprint_buttons
answer = []
for d in known_sequence:
	if d in intersect:
		answer.append(str(d))
print(' '.join(answer))


(n, m) = map(int, input().split())
nums = [int(i) for i in input().split()]
fp = [int(i) for i in input().split()]
ind = []
for i in fp:
	if i in nums:
		ind.append(nums.index(i))
ind.sort()
ans = ''
for i in ind:
	ans += str(nums[i]) + ' '
print(ans)


(n, m) = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
b = [100000] * 10
for j in range(n):
	b[x[j]] = j
c = [0] * m
for i in range(m):
	c[i] = b[y[i]]
cc = sorted(zip(c, y))
for i in range(m):
	if cc[i][0] == 100000:
		break
	print(cc[i][1], end=' ')


s = input()
(n, m) = [int(i) for i in s.split()]
s = input()
seq = [int(i) for i in s.split()]
s = input()
k = [int(i) for i in s.split()]
ans = []
for i in seq:
	if i in k:
		ans += [i]
for i in ans:
	print(i, end=' ')


(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for i in a:
	if i in b:
		c.append(str(i))
print(' '.join(c))


(n, k) = input().split()
(n, k) = (int(n), int(k))
arr = [int(x) for x in input().split()]
arr2 = [int(y) for y in input().split()]
for i in arr:
	if i in arr2:
		print(i, end=' ')


input()
l = [int(x) for x in input().split()]
l2 = [int(x) for x in input().split()]
for ele in l:
	if ele in l2:
		print(ele, end=' ')


m = input()
x = input()
y = input()
ans = ''
keys = x.split()
finger = y.split()
for each in keys:
	if each in finger:
		ans += str(each) + ' '
print(ans)


n = input().split()
m1 = input().split()
m2 = input().split()
lm1 = []
lm2 = []
for i in range(int(n[0])):
	lm1.append(int(m1[i]))
for i in range(int(n[1])):
	lm2.append(int(m2[i]))
s = ''
for i in range(int(n[0])):
	if lm1[i] in lm2:
		s += str(lm1[i]) + ' '
print(s)


(a, b) = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
l = []
for i in range(0, len(c)):
	if c[i] in d:
		l.append(c[i])
print(*l)


(n, l) = map(int, input().split())
A = list(input().split())
B = list(input().split())
C = ''
for i in A:
	if i in B:
		C += i
print(' '.join(C))


input()
list1 = list(map(int, input().split()))
list2 = list(map(int, input().split()))
cnt = 0
ans = []
for a in list1:
	if a in list2:
		ans.append(str(a))
print(' '.join(ans))


max_len = 0
max_sub = []
nm = input().split(' ')
n = int(nm[0])
m = int(nm[1])
seq = input().split(' ')
for i in range(len(seq)):
	seq[i] = int(seq[i])
finger = input().split(' ')
for i in range(len(finger)):
	finger[i] = int(finger[i])
not_in_s = []
for s in seq:
	if s not in finger:
		not_in_s.append(s)
for n in not_in_s:
	seq.remove(n)
not_in_f = []
for f in finger:
	if f not in seq:
		not_in_f.append(f)
for n in not_in_f:
	try:
		finger.remove(f)
	except:
		pass
print(' '.join((str(x) for x in seq)))
used = [False for _ in range(len(finger))]
max_finger = []
for i in range(len(max_sub)):
	if max_sub[i]:
		max_finger.append(finger[i])


(size1, size2) = list(map(int, input().split()))
sequence = list(map(int, input().split()))
key_fp = list(map(int, input().split()))
result = []
for i in sequence:
	if i in key_fp:
		result.append(i)
print(*result)


entrada = input().split()
n = int(entrada[0])
m = int(entrada[1])
sequence = input().split()
sequence = [int(x) for x in sequence]
fingerprints = input().split()
fingerprints = [int(x) for x in fingerprints]
ans = []
for digit in sequence:
	if digit in fingerprints:
		ans.append(digit)
print(' '.join([str(x) for x in ans]))


list1 = []
fig = []
(n, m) = map(int, input().split())
list1 = list(map(int, input().split()))
fig = list(map(int, input().split()))
for j in range(n):
	for t in range(m):
		if fig[t] == list1[j]:
			print(fig[t], end=' ')


(n, m) = map(int, input().strip().split(' '))
arr = list(map(int, input().strip().split(' ')))
brr = list(map(int, input().strip().split(' ')))
ans = []
for i in arr:
	if i in brr:
		ans.append(i)
for i in ans:
	print(i, end=' ')


input()
x = input().split()
y = input().split()
v = []
for i in x:
	if i in y:
		v.append(i)
print(*v)


n = input()
k = list(map(int, input().split()))
p = list(map(int, input().split()))
result = []
for e in k:
	if e in p:
		result.append(e)
print(' '.join(map(str, result)))


(n, k) = map(int, input().split(' '))
a = list(map(str, input().split(' ')))
s = list(map(str, input().split(' ')))
ans = []
for x in a:
	if x in s:
		ans.append(x)
ans = ' '.join(ans)
print(ans)


def f(x):
	global a
	if x in a:
		return a.index(x)
	else:
		return 100000
(n, m) = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
b.sort(key=f)
for el in b:
	if el in a:
		print(el, end=' ')


(n, m) = (int(x) for x in input().split())
s = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]
ans = []
for x in s:
	if x in t:
		ans.append(x)
print(*ans)


(n, m) = map(int, input().split())
X = [int(x) for x in input().split()]
Y = set((int(x) for x in input().split()))
A = []
for x in X:
	if x in Y:
		A.append(x)
print(*A)


(n, m) = list(map(int, input().split()))
number = list(map(int, input().split()))
finger = list(map(int, input().split()))
for i in number:
	if i in finger:
		print(i, end=' ')


try:
	(n, m) = map(int, input().split())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l3 = []
	for i in l1:
		if l2.count(i) > 0:
			l3.append(i)
	print(*l3)
except EOFError:
	pass


(n, k) = list(map(int, input().split()))
po = list(map(int, input().split()))
ko = list(map(int, input().split()))
lo = []
so = []
tan = []
x = 0
for item in ko:
	if item in po:
		so.append(item)
		lo.append(po.index(item))
		po[po.index(item)] = 55555555
	else:
		pass
for item in lo:
	tod = lo.index(min(lo))
	tan.append(so[tod])
	lo[tod] = 555555
print(*tan)


nm = input()
line1 = input().split()
line2 = input().split()
for i in line1:
	if i in line2:
		print(i, end=' ')


(n, m) = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
d = [0] * 11
for i in range(m):
	d[y[i]] = 1
v = []
for i in range(n):
	if d[x[i]] == 1:
		v.append(x[i])
		d[x[i]] = 2
for i in range(len(v)):
	print(v[i], end=' ')


s = []
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(0, n):
	for k in range(0, m):
		if a[i] == b[k]:
			s.append(a[i])
			n += 1
if n == 0:
	print('-')
else:
	print(*s)


def two(a, b):
	s = set(b)
	return [x for x in a if x in s]
(i, j) = [int(k) for k in input().split()]
lst1 = [int(y) for y in input().split()]
lst2 = [int(z) for z in input().split()]
print(*two(lst1, lst2))


(n, m) = map(int, input().split())
mat = list(map(int, input().split()))
sat = list(map(int, input().split()))
for i in mat:
	if i in sat:
		sat.remove(i)
		print(i, end=' ')


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
k = list(map(int, input().split()))
ind = []
for i in range(m):
	if k[i] in l:
		ind.append(l.index(k[i]))
ind.sort()
for i in ind:
	print(l[i], end=' ')


(n, m) = map(int, input().split())
dlin = list(map(int, input().split()))
est = list(map(int, input().split()))
k = []
for i in dlin:
	if i in est:
		k.append(i)
print(*k)


(n, m) = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
z = []
for i in range(n):
	for j in range(m):
		if x[i] == y[j]:
			z.append(x[i])
if len(z) != 0:
	for i in range(len(z)):
		print(z[i], end=' ')
else:
	print()


inp = input()
inp = inp.split(' ')
list_one = input()
list_one = list_one.split(' ')
list_two = input()
list_two = list_two.split(' ')
answer = ''
for current_number in list_one:
	if current_number in list_two:
		answer += current_number + ' '
print(answer)


def test():
	(a, b) = map(int, input().split())
	n = list(map(int, input().split()))
	m = list(map(int, input().split()))
	res = []
	for x in n:
		if x in m:
			res.append(x)
	print(*res)
test()


(N, K) = map(int, input().split(' '))
L = list(map(int, input().split(' ')))
L1 = list(map(int, input().split(' ')))
C = []
for i in range(0, K):
	if L1[i] in L:
		W = L.index(L1[i])
		C.append(W)
C = sorted(C)
for i in range(0, len(C)):
	R = C[i]
	print(L[R], end=' ')
print()


h = input()
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
for x in a:
	if x in b:
		print(x, ' ', end='')


(n, m) = map(int, input().split())
x = list(map(int, input().split()))
d = dict.fromkeys(x, False)
tmp = list(map(int, input().split()))
for i in range(m):
	if tmp[i] in d:
		d[tmp[i]] = True
for (k, v) in d.items():
	if v == True:
		print(k, end=' ')


(n, m) = map(int, input().split())
mas = list(map(int, input().split()))
gas = list(map(int, input().split()))
fas = []
for el in mas:
	if el in gas:
		fas.append(str(el))
if len(fas) != 0:
	print(' '.join(fas))


class fingerprints:

	def __init__(self, n, m):
		self.n = n
		self.m = m
		self.calculateCode(self.n, self.m)

	def calculateCode(self, n, m):
		list1 = []
		list2 = []
		p = input()
		q = input()
		list1 = list(p.split())
		list2 = list(q.split())
		list3 = list1.copy()
		for x in list1:
			if x in list1:
				if x not in list2:
					list3.remove(x)
		for x in list3:
			print(int(x), end=' ')
(n, m) = map(int, input().split())
if 1 <= n and m <= 10:
	pass
else:
	exit()
fingerprintsObj = fingerprints(n, m)


l = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
for i in p:
	if i in q:
		print(i, end=' ')


param = list(map(int, input().split()))
(n, m) = (param[0], param[1])
X = input().split()
Y = set(input().split())
res = []
for i in range(n):
	if X[i] in Y:
		res.append(X[i])
print(' '.join(res))


input()
l = list(map(int, input().split()))
s = set(map(int, input().split()))
ans = []
for e in l:
	if e in s:
		ans.append(e)
print(*ans)


(N, M) = input().split()
n = input().split()
phn = n[:]
m = input().split()
for each in phn:
	if each not in m:
		n.remove(each)
for each in n:
	print(each, end=' ')


def answer():
	a = input()
	b = input().split()
	c = input().split()
	d = [x for x in b if x in c]
	c = ''
	i = 0
	while i < len(d):
		c += d[i]
		i += 1
		if i != len(d):
			c += ' '
	print(c)
answer()


(n, m) = input().split()
(n, m) = (int(n), int(m))
a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]
c = []
for i in range(n):
	if a[i] in b:
		c.append(a[i])
print(*c)


from itertools import filterfalse
input()
x = input().split()
y = input().split()
print(*filterfalse(lambda a, b=y: a not in b, x))


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
a = list(map(int, input().split()))
d = ''
for i in l:
	if i in a:
		d += str(i) + ' '
print(d)


(a, b) = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
for i in range(len(x)):
	for j in range(len(y)):
		if x[i] == y[j]:
			print(y[j], end=' ')


(a, b) = map(int, input().split())
li = list(map(int, input().split()))
li2 = list(map(int, input().split()))
for i in range(a):
	if li[i] in li2:
		print(li[i], end=' ')


(n, m) = map(int, input().split())
seq = [i for i in map(int, input().split())]
finger = [i for i in map(int, input().split())]
temp = []
for i in set(seq).intersection(set(finger)):
	temp.append(seq.index(i))
temp.sort()
for i in temp:
	print(seq[i], end=' ')


(n, m) = [int(x) for x in input().split()]
list3 = []
list1 = list([int(x) for x in input().split()])
list2 = list([int(y) for y in input().split()])
for a in list1:
	if a in list2:
		list3.append(a)
for value in list3:
	print(value, end=' ')


def fonction(liste1, liste2):
	d = []
	for i in range(len(liste1)):
		if liste2.count(liste1[i]) == 1:
			d.append(liste1[i])
		else:
			pass
	return d
(n, m) = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
print(*fonction(a, b))


def inp():
	return map(int, input().split())
import sys
import math
(n, m) = inp()
a = list(inp())
b = list(inp())
ans = []
for i in a:
	if i in b:
		ans.append(i)
print(*ans)


(n, m) = input().split()
n = int(n)
m = int(m)
key = list(map(int, input().split()))
finger = list(map(int, input().split()))
for i in range(0, n):
	if key[i] in finger:
		print(key[i], end=' ')


class CodeforcesTask994ASolution:

	def __init__(self):
		self.sequence = []
		self.fingerprints = []
		self.result = ''

	def read_input(self):
		input()
		self.sequence = input().split(' ')
		self.fingerprints = input().split(' ')

	def process_task(self):
		for number in self.sequence:
			if number in self.fingerprints:
				self.result += ' {0}'.format(number)

	def get_result(self):
		return self.result[1:]
Solution = CodeforcesTask994ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


(n, m) = [int(s) for s in input().split()]
x_mas = [int(s) for s in input().split()]
y_mas = {int(s) for s in input().split()}
ans_mas = []
for x in x_mas:
	if x in y_mas:
		ans_mas.append(x)
print(' '.join([str(x) for x in ans_mas]))


z = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
count = 0
for i in x:
	for j in range(len(y)):
		if i == y[j]:
			count += 1
			if count == len(y):
				print(i)
			else:
				print(i, end=' ')


(n, m) = map(int, input().split())
x = input().split()
y = input().split()
a = filter(lambda i: i in y, x)
print(*a)


(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = []
for ai in a:
	if ai in b:
		ans.append(str(ai))
if len(ans) >= 1:
	print(' '.join(ans))
else:
	print()


(a, b) = map(int, input().split())
seq = list(map(int, input().split()))
fin = list(map(int, input().split()))
for item in seq:
	c = item
	for item in fin:
		if c == item:
			print(c, end=' ')


n_m = input()
string = ''
s = input().split()
f = input().split()
for check in s:
	if check in f:
		check += ' '
		string += check
print(string)


(ls1, ls2) = map(int, input().split())
s1 = list(input().split())
s2 = list(input().split())
c = 0
l = []
for i in s1:
	for j in s2:
		if i == j:
			l.append(j)
for i in l:
	print(i, end=' ')


(n, m) = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
res = [-1] * 10
for i in y:
	if i in x:
		res[x.index(i)] = i
for i in res:
	if i != -1:
		print(i, end=' ')


(n, m) = map(int, input().split())
set_n = [int(x) for x in input().split()]
set_m = [int(x) for x in input().split()]
for elements in set_n:
	if elements in set_m:
		print(elements, end=' ')


(n, m) = input().split()
n = int(n)
m = int(m)
a = list(map(int, input().split()))
b = list(map(int, input().split()))
k = set(a)
l = set(b)
j = k & l
for x in a:
	if x in j:
		print(x, end=' ')


(n, m) = map(int, input().split())
s = list(map(int, input().split()))
f = list(map(int, input().split()))
for a in s:
	if f.count(a) > 0:
		print(a, end=' ')


(n, m) = map(int, input().split())
sequence = list(map(int, input().split()))
fingerprints = list(map(int, input().split()))
result = []
for num in sequence:
	if num in fingerprints:
		result.append(str(num))
print(' '.join(result))


input()
seq = input().split()
fprint = set(input())
print(*[e for e in seq if e in fprint])


(n, m) = map(int, input().split())
s = list(map(int, input().split()))
k = set(map(int, input().split()))
r = [i for i in s if i in k]
print(*r)


(n, m) = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
arr = []
for item in y:
	if item in x:
		arr.append((x.index(item), item))
arr.sort()
for item in arr:
	print(item[1], end=' ')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
q = [0] * 10
ans = []
for i in b:
	q[i] += 1
for i in a:
	if q[i] != 0:
		ans.append(i)
		q[i] -= 1
for i in range(len(ans)):
	print(ans[i], end=' ')
print()


import math
(n, m) = input().split()
n = int(n)
m = int(m)
ans = []
s = ''
x = input().split()
y = input().split()
for i in range(len(y)):
	s = s + str(y[i])
for i in range(len(x)):
	if s.find(str(x[i])) != -1:
		ans.append(int(x[i]))
for i in range(len(ans)):
	print(ans[i], end=' ')


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
m = list(map(int, input().split()))
for j in l:
	if j in m:
		print(j, end=' ')


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = set(map(int, input().split()))
o = ''
for i in a:
	if i in b:
		o += str(i) + ' '
print(o)


input()
ar1 = list(map(int, input().split()))
ar2 = set(list(map(int, input().split())))
ans = []
for a in ar1:
	if a in ar2:
		ans += [a]
for a in ans:
	print(a, end=' ')


a = input().split(' ')
b = input().split(' ')
c = input().split(' ')
(n, m) = (int(a[0]), int(a[1]))
code = []
for impr in b:
	if impr in c:
		code.append(impr)
	else:
		print()
print(*code, end='')


(n, m) = input().split()
n = int(n)
m = int(m)
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = ''
for i in a:
	if i in b:
		c += str(i) + ' '
c = c.rstrip()
print(c)


from functools import reduce
lenOfArr = list(map(lambda x: int(x), input().split()))
arr = list(map(lambda x: int(x), input().split()))
targetArr = list(map(lambda x: int(x), input().split()))
res = []
for i in arr:
	if i in targetArr:
		res.append(str(i))
if len(res) == 0:
	print()
else:
	print(reduce(lambda x, y: x + ' ' + y, res))


(n, m) = [int(x) for x in input().split()]
num = [int(x) for x in input().split()]
op = [int(x) for x in input().split()]
fin = []
for x in num:
	if x in op:
		fin.append(str(x))
print(' '.join(fin))


a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = []
for i in range(len(c)):
	if c[i] in b:
		x = b.index(c[i])
		d.append(x)
d.sort()
for j in range(len(d)):
	print(b[d[j]], end=' ')


(n, m) = map(str, input().split())
seq = list((int(x) for x in input().split()))
fingerprint = list((int(x) for x in input().split()))
for x in seq:
	if x in fingerprint:
		print(x, end=' ')


def digit_sequence(sequence, fingerprints):
	code = []
	for element in sequence:
		if element in fingerprints:
			code.append(element)
	return code
(n, m) = map(int, input().split())
sequence = list(map(int, input().split()))
fingerprints = list(map(int, input().split()))
print(' '.join(map(str, digit_sequence(sequence, fingerprints))))


import sys
(n, m) = input().split(' ')
n = int(n)
a = []
b = []
a = input().split(' ')
b = input().split(' ')
for i in range(n):
	if a[i] in b:
		sys.stdout.write(a[i] + ' ')
print('')


(n, m) = map(int, input().split())
a = list(map(int, input().split()))[:n]
b = list(map(int, input().split()))[:m]
q = []
for i in range(0, n):
	for j in range(0, m):
		if a[i] == b[j]:
			q.append(a[i])
for i in range(0, len(q)):
	print(q[i], end=' ')


def FingerPrints(seq, fp):
	result = ''
	for d in seq:
		if d in fp:
			result += str(d)
			result += ' '
	return result[0:len(result) - 1]
(n, m) = [int(x) for x in input().split()]
seq = [int(x) for x in input().split()]
fp = [int(x) for x in input().split()]
print(FingerPrints(seq, fp))


import sys
import math
(n, m) = map(int, input().split())
seq = [int(x) for x in input().strip().split()]
finger = [int(y) for y in input().strip().split()]
for i in range(len(seq)):
	for j in range(len(finger)):
		if seq[i] == finger[j]:
			print(seq[i], end=' ')


(n, m) = map(int, input().split())
lx = [int(i) for i in input().split()]
ly = [int(i) for i in input().split()]
s = list(set(lx) and set(ly))
for i in lx:
	if i in s:
		print(i, end=' ')
print()


import math
(n, m) = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
s = set()
for elem in y:
	s.add(elem)
for elem in x:
	if elem in s:
		print(elem, end=' ')


(n, m) = map(int, input().split())
sequence = list(map(int, input().split()))
fingerprint = list(map(int, input().split()))
res = []
for i in sequence:
	if i in fingerprint:
		res.append(i)
for i in res:
	print(i, end=' ')


(n, m) = map(int, input().split())
ikn = list(map(int, input().split()))
stp = list(map(int, input().split()))
code = []
for i in range(n):
	if ikn[i] in stp:
		code.append(ikn[i])
for i in range(len(code)):
	print(code[i], end=' ')


(n, m) = map(int, input().split())
seq = list(map(int, input().split()))
fingers = list(map(int, input().split()))
password = []
for i in seq:
	if i in fingers:
		password.append(i)
for i in password:
	print(i, end=' ')


from __future__ import print_function
from queue import Queue
import sys
import math
import os.path

def log(*args, **kwargs):
	print(*args, file=sys.stderr, **kwargs)

def ni():
	return map(int, input().split())

def nio(offset):
	return map(lambda x: int(x) + offset, input().split())

def nia():
	return list(map(int, input().split()))

def toString(aList, sep=' '):
	return sep.join((str(x) for x in aList))

def toMapInvertIndex(aList):
	return {k: v for (v, k) in enumerate(aList)}
(n, m) = ni()
x = nia()
y = nia()
s = []
for xi in x:
	if xi in y:
		s += [xi]
print(toString(s))


def main():
	useless = input()
	(x, y) = (list(map(int, input().split())), list(map(int, input().split())))
	(x, y) = (list(filter(lambda a: a in y, x)), list(filter(lambda a: a in x, y)))
	if x and y:
		ans = []
		for i in x:
			if i in y:
				ans.append(i)
		print(' '.join([str(i) for i in ans]))
		return 0
	print('')
	return 0
main()


(n, m) = map(int, input().split())
a = [int(x) for x in input().split()]
k = [int(x) for x in input().split()]
l = []
f = []
for i in range(len(k)):
	if k[i] in a:
		l.append(a.index(k[i]))
l.sort()
for i in range(len(l)):
	f.append(a[l[i]])
for i in range(len(f)):
	print(f[i], end=' ')


(n, m) = map(int, input().split())
seq = ''.join(list(input().split()))
known = input().split()
for i in range(10):
	c = str(i)
	if c not in known:
		seq = seq.replace(c, '')
print(' '.join(seq))


(n, m) = [int(x) for x in input().split()]
s = [int(x) for x in input().split()]
q = [int(x) for x in input().split()]
a = []
for i in range(n):
	if s[i] in q:
		a.append(s[i])
print(*a)


inp = input().split()
x = input().split()
y = input().split()
printed = False
for i in range(0, int(inp[0])):
	if x[i] in y:
		if printed:
			print(' ', end='')
		printed = True
		print(x[i], end='')
print()


n = list(map(int, input().split()))
a = list(map(int, input().split()[:n[0]]))
b = list(map(int, input().split()[:n[1]]))
for i in a:
	for j in b:
		if i == j:
			print(i, end=' ')


l = list(map(int, input().split()))
n = l[0]
m = l[1]
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
for i in l1:
	if i in l2:
		print(i, end=' ')


(n, my) = input().split()
sequence = input().split()
fingerprintedNumbers = input().split()
res = []
for number in sequence:
	if number in fingerprintedNumbers:
		res.append(number)
print(' '.join(res))


def do():
	(n, k) = map(int, input().split())
	datn = list(map(int, input().split()))
	datm = list(map(int, input().split()))
	res = []
	for i in range(n):
		if datn[i] in datm:
			res.append(datn[i])
	print(' '.join(list(map(str, res))))
do()

def resolve():
	from pprint import pprint
	q = int(input())
	for _ in range(q):
		s = input()
		n = int(input())
		(n, k) = map(int, input().split())
		dat = list(map(int, input().split()))
	dat = [1, 2, 3]
	print(' '.join(list(map(str, res))))
	pass
	import math
	math.ceil(1.2)
	math.floor(1.2)
	round(1.2, 3)


(a, b, c) = (input().split(), input().split(), input().split())
print(' '.join([i for i in b if i in c]))


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
z = []
for q in range(n):
	if a[q] in b:
		z.append(a[q])
print(*z)


(m, n) = map(int, input().split())
L = list(map(int, input().split()))
F = list(map(int, input().split()))
for i in range(m):
	for j in range(n):
		if L[i] == F[j]:
			print(L[i], end=' ')


nm = list(map(int, input().split()))
n = nm[0]
m = nm[1]
q = list(map(int, input().split()))
p = list(map(int, input().split()))
l = []
for i in p:
	if i in q:
		l.append(q.index(i))
l.sort()
for k in l:
	print(q[k], end=' ')


(n, m) = (int(t) for t in input().split())
x = [int(t) for t in input().split()]
y = [int(t) for t in input().split()]
rs = []
for i in x:
	if i in y:
		rs.append(i)
print(' '.join((str(e) for e in rs)))


[n, m] = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = ''
for i in a:
	if i in b:
		s = s + str(i) + ' '
print(s[0:len(s)])


n = input()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in a:
	for x in b:
		if x == i:
			print(i, end=' ')


(n, m) = map(int, input().split())
x = [*map(int, input().split())]
have = [False] * 10
for i in map(int, input().split()):
	have[i] = True
for i in x:
	if have[i]:
		print(i, end=' ')


a = list(map(int, input().split()))
x = list(map(int, input().split()))
y = set(list(map(int, input().split())))
ans = []
for elem in x:
	if elem in y:
		ans.append(elem)
print(*ans)


input()
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
for x in a:
	if x in b:
		print(x, end=' ')
print()


(n, k) = map(int, input().split())
l = input()
l = [int(i) for i in l.split()]
x = input()
x = [int(i) for i in x.split()]
ans = []
for i in x:
	if i in l:
		ans.append(l.index(i))
ans.sort()
for i in ans:
	print(l[i], end=' ')


(n, c) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = []
for i in range(0, len(a)):
	if a[i] in b:
		ans.append(a[i])
for i in range(0, len(ans)):
	print(ans[i], end=' ')


(n, k) = map(int, input().split())
a1 = [int(x) for x in input().split()]
a2 = [int(x) for x in input().split()]
new = []
for i in a1:
	if i in a2:
		new.append(i)
print(*new)


(n, m) = (int(i) for i in input().split())
l = [int(i) for i in input().split()]
l1 = [int(i) for i in input().split()]
l2 = []
for i in l:
	if i in l1:
		l2.append(i)
print(*l2)


def Fingerprint():
	(n, m) = list(map(int, input().split()))
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	nums = []
	for num in x:
		if num in y:
			nums.append(num)
	print(' '.join((str(number) for number in nums)))
Fingerprint()


(n, m) = map(int, input().split())
a = list(input().split())
b = list(input().split())
z = list()
for i in range(n):
	if a[i] in b:
		z.append(a[i])
k = str()
for i in range(len(z)):
	k += str(z[i]) + ' '
print(k)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
q = set(list(map(int, input().split())))
ans = []
for i in a:
	if i in q:
		ans.append(i)
print(*ans)


(n, m) = list(map(int, input().split()))
s = list(map(int, input().split()))
s1 = list(map(int, input().split()))
ans = []
for i in s:
	if i in s1:
		ans.append(i)
for i in ans:
	print(i, end=' ')


(n, m) = map(int, input().split())
l = [int(i) for i in input().split()]
s = [int(i) for i in input().split()]
for i in range(n):
	for j in range(m):
		if l[i] == s[j]:
			print(l[i], end=' ')


(n, m) = (int(v) for v in input().split())
list1 = [u for u in input().split()]
list2 = [t for t in input().split()]
ans = ''
for i in range(len(list1)):
	if list1[i] in list2:
		ans += list1[i] + ' '
	else:
		pass
print(ans.rstrip(' '))


(n, m) = input().split(' ')
x = input().split(' ')
y = input().split(' ')
print(*[u for u in x if u in y])


(n, m) = map(int, input().split())
list1 = list(map(int, input().split()))
list2 = list(map(int, input().split()))
list3 = []
for _ in range(n):
	for i in range(m):
		if list1[_] == list2[i]:
			list3.append(list1[_])
print(*list3, sep=' ')


(n, m) = input().split()
x = list(map(int, input().split()))
y = list(map(int, input().split()))
lenx = len(x)
for i in range(lenx):
	if x[i] in y:
		print(x[i], end=' ')
print()


def s():
	(n, m) = [int(x) for x in input().split(' ')]
	n = [int(x) for x in input().split(' ')]
	m = [int(x) for x in input().split(' ')]
	ans = []
	for x in n:
		if x in m:
			ans.append(x)
	for x in ans:
		print(x, end=' ')
s()


(n, m) = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
ans = ''
for i in range(n):
	if x[i] in y:
		ans += str(x[i]) + ' '
print(ans)


(a, b) = input().split()
(a, b) = (int(a), int(b))
arr = list(map(int, input().split()))
a2 = list(map(int, input().split()))
for i in arr:
	if i in a2:
		print(i, end=' ')


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
ll = list(map(int, input().split()))
ans = []
for i in range(n):
	if l[i] in ll:
		ans.append(l[i])
print(*ans)


(n, m) = input().split()
n = int(n)
m = int(m)
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = {}
for c in b:
	try:
		d[c] += 1
	except:
		d[c] = 1
e = []
for c in a:
	try:
		if d[c] >= 1:
			e.append(c)
			d[c] -= 1
	except:
		pass
for c in e:
	print(c, end=' ')


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
f = list(map(int, input().split()))
for i in range(0, len(l)):
	for j in range(0, len(f)):
		if f[j] == l[i]:
			print(l[i], end=' ')
		else:
			pass


(n, m) = [int(x) for x in input().strip().split()]
s = [int(x) for x in input().strip().split()]
t = set([int(x) for x in input().strip().split()])
for si in s:
	if si in t:
		print(si, end=' ')
		t.remove(si)