n , m =list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x, y = min(a), min(b)
if (x in b and y in a):
    if (x < y):
        print(x)
    else:
        print(y)
elif (x in b and y not in a):
    print(x)
elif (x not in b and y in a):
    print(y)
else:
    print(str(x) + str(y))
