a, b = map(int,input().split())

n = [None] * a
m = [None] * b

n = list(map(int,input().split()))
m = list(map(int,input().split()))
    
if min(n) > min(m) and min(m) != 0:
    print(min(m),end='')
    print(min(n))
    
elif min(n) == min(m):
    print(min(n))
    
else:
    if min(n) != 0:
        print(min(n),end='')
        print(min(m))
    else:
        print(min(m),end='')
        print(min(n))        