a=input()
b=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]
for i in range(1,100):
    if i<10:
        if i in b and i in c:
            print(i)
            break
    else:
        if i//10 in b and i%10 in c:
            print(i)
            break
        elif i//10 in c and i%10 in b:
            print(i)
            break