n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
num = 0
for i in range(1, 10):
    if i in a and i in b:
        num = i
        break

if num != 0:
    print(num)
else:
    a = sorted(a)
    b = sorted(b)
    s = 10 * a[0] + b[0]
    t = 10 * b[0] + a[0]
    if s <= t:
        print(s)
    else:
        print(t)