input()
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l1 = sorted(l1)
l2 = sorted(l2)
for i in l1:
    if i in l2:
        print(i)
        exit(0)
if min(l1) > min(l2):
    print(str(min(l2))+ str(min(l1)))
else:
    print(str(min(l1)) + str(min(l2)))
