input()
arr1 = [i for i in sorted(list(map(int, input().split(' ')))) if i != 0]
arr2 = [i for i in sorted(list(map(int, input().split(' ')))) if i != 0]
if arr1[0] < arr2[0]:
    print(int(str(arr1[0])+ str(arr2[0])))
elif arr1[0] > arr2[0]:
    print(int(str(arr2[0]) + str(arr1[0])))
else:
    print(arr1[0])
