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