n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
for i in range(1, 10000):
    num = str(i)
    a1 = False
    b1 = False
    for k in num:
        if int(k) in a:
            a1 = True
        if int(k) in b:
            b1 = True
    if a1 and b1:
        print(i)
        exit()
