nm = input()
x = sorted(list(map(int, input().split())))
y = sorted(list(map(int, input().split())))

out = False

for i in x:
    if i in y:
        print(i)
        out = True
        break
    
if not out:
    a = x[0]
    b = y[0]
    a,b = min(a,b), max(a,b)
    a = (a*10)+b
    print(a)

