n, m = map(int, input().split(' '))
first = list(input().split(' '))
second = list(input().split(' '))

answer = 0

i = 0
while True and not answer:
    s = str(i)
    trigg = False
    for j in first:
        if j in s:
            trigg = True
            break
    if trigg:
        for k in second:
            if k in s:
                answer = i
                break
    i += 1

print(answer)