n,m=map(int,input().split())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
a=min(l1)
b=min(l2)
if min(a,b) in l1 and min(a,b) in l2:
	print(min(a,b))
elif max(a,b) in l1 and max(a,b) in l2:
	print(max(a,b))
else:
	print(str(min(a,b))+str(max(a,b)))