n,m=tuple([int(i) for i in input().split()])
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
x=min(a)
y=min(b)
if (x>y):
    x,y=y,x
    res=x*10+y
elif x<y:
    res=x*10+y
elif x==y:
    res=x
print(res)
