n,m=map(int,raw_input().split())
l1=map(int,raw_input().split())
l2=map(int,raw_input().split())

l1.sort()
l2.sort()
a=set([l1[0],l2[0]])
num=0
a=list(a)
a.sort()
for x in a:
	num*=10
	num+=x
print num
