n, m = map(int, input().split())
a = map(int, input().split())
b = map(int, input().split())
a=list(a)
b=list(b)
min_a = min(a)
min_b = min(b)
min_A = min(min_a, min_b)
min_B = max(min_a, min_b)
if min_A==min_A:
    print (min_A)
else:
    print(10*min_A+min_B)
