
n,m = map(int,raw_input().split())

A = map(int,raw_input().split())
B = map(int,raw_input().split())

a=min(A)
b=min(B)
if a==0 and b==0:
    print 0
elif a==0:
    print 10*b
elif b==0:
    print 10*a
else:
    print min(10*a+b,10*b+a)



