a,b=input().split(" ")
a=int(a)
b=int(b)
str_in1 = input()
str_in2 = input()
numa=[a]
numa = [int(n) for n in str_in1.split()] 
numb=[b]
numb = [int(n) for n in str_in2.split()] 
numa.sort()
numb.sort()
i=0
j=0
flag=0
pp=[]
while(i<a):
    j=0
    while(j<b):
        if(numa[i]==numb[j]):
            pp.append(numa[i])
            flag=1
        j+=1
    i+=1
if(flag==1):
    pp.sort()
    print(pp[0])
if(flag==0):
    print(str(min(numa[0],numb[0]))+str(max(numa[0],numb[0])))