a, b = [int(x) for x in input().split()]
a1 = [int(x) for x in input().split()]
b1 = [int(x) for x in input().split()]
start = '0'
while True:
    if len(start) == 1:
        if int(start) in a1 and int(start) in b1:
            break
    else:
        if int(start[0]) in a1:
            if int(start[1]) in b1:
                break
        if int(start[0]) in b1:
            if int(start[1]) in a1:
                break
    start = str(int(start) + 1)
print(start)
