n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
flag=0
y=[]
x=[min(a),min(b)]
for i in range(n):
	if a[i] in b:
		y.append(a[i])
		flag=1
if flag==0:
	print(*sorted(x),sep='')
elif flag==1:
	print(min(y))