n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))

flag=0
l=[]
for i in range(len(a)):
	if a[i] in b:
		flag=1
		l.append(a[i])

x=min(a)
y=min(b)
u=min(x,y)
v=max(x,y)

if flag==1:
	print(min(l))
else:
	print(u,end='')
	print(v)