n, m = map(int,input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
z_1 = min(a)
z_2 = min(b)
if z_1 == z_2:
    ans = z_1
elif z_1 > z_2:
    ans = z_2*10 + z_1
else:
    ans = z_1*10 + z_2

print(ans)