n, m = [int(i) for i in input().split()]
a1 = min([int(i) for i in input().split()])
a2 = min([int(i) for i in input().split()])

if (a1 == a2):
    print(a1)
else:
    print(str(min(a1, a2))+str(max(a1, a2)))