a,b=input().split()
a=int(a)
b=int(b)
c=input().split()
m=input().split()
min1=10000
min2=10000
k=[]
for i in range(a):
    if(int(c[i])<=min1):
        min1=int(c[i])
for i in range(b):
    if(int(m[i])<=min2):
        min2=int(m[i])
fl=1
min=100
for i in range (b):
    for j in range(a):
        if(m[i]==c[j]):
            min1=int(m[i])
            min2=int(m[i])
        if (min1 == min2 and min > int(min1)):
            min = min1
if(min!=100):
    print(min,sep='',end='')
elif(min1 == min2):
    print(min1,sep='',end='')
elif(min1<min2):
    print(min1,min2,sep='',end='')
else:
    print(min2,min1,sep='',end='')