s1 = str (input())
s2 = str (input())
s3 = str (input())
c = []
c = s1.split()
n = int (c[0])
m = int (c[1])


a = []
b = []
a = s2.split()
b = s3.split()
for i in range (n):
    a[i] = int (a[i])

   
i = 0
for i in range (m):
    b[i] = int (b[i])

minn = 10
for i in range (n):
    if ((a[i] in b) == 1):
        if (a[i] < minn):
            minn = a[i]

if (minn != 10):
    if (min(a) > min (b)):
        if ((min(b)*10 + min(a)) < minn):
            print (min(b)*10 + min(a))
        else:
            print (minn)
    elif (min(b) > min (a)):
        if ((min(a)*10 + min(b)) < minn):
            print (min(a)*10 + min(b))
        else:
            print (minn)
    else:
        print (min(a))
    
else:
    if (min(a) > min (b)):
        print (min(b)*10 + min(a))
    elif (min(b) > min (a)):
            print (min(a)*10 + min(b))
    else:
        print (min(a))
