# import sys
# sys.stdin=open("input.in","r")
n,k=map(int,input().split())
l=set(map(int,input().split()))
k=set(map(int,input().split()))
x=min(l)
y=min(k)
e=l&k
if len(e)!=0:
	print(min(e))
else:
	print(min(x,y),max(x,y),sep="")