n,m = input().split()
list1 = sorted(map(int, input().split()))
list2 = sorted(map(int, input().split()))
b =set(list1)
c = set(list2)
if(b.intersection(c)):
    print(min(b.intersection(c)))
else:
    if(list1[0] < list2[0]):
        print("%d%d"%(list1[0], list2[0]))
    else:
        print("%d%d"%(list2[0], list1[0]))
