n,m = [int(i) for i in input().split()]
a1 = [int(i) for i in input().split()]
a2 = [int(i) for i in input().split()]

pr = 1

while True:

    if(pr<10):
        if(pr in a1 and pr in a2):
            print(pr)
            break
    elif((pr//10 in a1 and pr%10 in a2) or (pr//10 in a2 and pr%10 in a1)):
        print(pr)
        break
    pr+=1
    