a,b=map(int,input().split())
list1=list(map(int,input().split()))
list2=list(map(int,input().split()))
t=0
list1.sort()
list2.sort()
for i in range(a):
    for j in range(b):
        if (list1[i]==list2[j]):
            t=1
            break
    if t==1:break
if t==1:
    print(list1[i])
else:
    a=list1[0]
    b=list2[0]
    if (a*10+b)>(b*10+a):
        print(b*10+a)
    else :
        print(a*10+b)