n, m = map(int, input().split())
s1 = list(map(int, input().split()))
s2 = list(map(int, input().split()))
flag = 0
for i in range(1, 100):
    for j in range(n):
        for k in range(m):
            if (i // 10 == s1[j] or i % 10 == s1[j]) and (i // 10 == s2[k] or i % 10 == s2[k]):
                print(i)
                flag = 1
                break
        if flag:
            break
    if flag:
        break