a = input().split()
n = int(a[0])
m = int(a[1])
b1 = list(map(int,input().split()))
b2 = list(map(int,input().split()))
q = [1,2,3,4,5,6,7,8,9]
fl = True
for i in q:
    if i in b1 and i in b2:
        print(i)
        fl = False
        break

if fl == True:
    
    if min(b1) > min(b2) :
        print(str(min(b2))+str(min(b1)))
    elif min(b1) < min(b2) :
        print(str(min(b1))+str(min(b2)))
    
