input()

a = list(map(int, input().split()))
b = list(map(int, input().split()))

for i in sorted(a):
    if(i in b):
        print (i)
        quit()

if(sorted(a)[0] < sorted(b)[0]):
    print(str(sorted(a)[0]) + str(sorted(b)[0]))
else:
    print(str(sorted(b)[0]) + str(sorted(a)[0]))