n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
for i in range(1, 100):
    if len(str(i)) == 1:
        if (i in a) and (i in b):
            print(i)
            exit()
    else:
        t1 = int(str(i)[0])
        t2 = int(str(i)[1])
        if (t1 in a and t2 in b) or (t2 in a and t1 in b):
            print(i)
            exit()