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]
arrO = sorted([i for i in arr1 if i in arr2])
if len(arrO) > 0:
    print(arrO[0])
elif 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])))
