la, lb = list(map(int, input().split(' ')))
a = input().split(" ")
b = input().split(" ")

i = 0
while True:
    e = list(str(i))
    e1 = len(list(filter(lambda x: x in e, a)))
    e2 = len(list(filter(lambda x: x in e, b)))
    if e1 > 0 and e2 > 0:
        print(i)
        break
    i+=1
