n,m=map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print
if min(a)<min(b):
    print(min(a)*10+min(b))
elif min(a)==min(b):
    print(min(a))
else:
    print(min(b)*10+min(a))
