input()
daf1 = set(list(map(int, input().split())))
daf2 = set(list(map(int, input().split())))

daf3 = daf1.intersection(daf2)

if len(daf3) > 0:
    print(min(daf3))
else:
    x = min(daf1)
    y = min(daf2)
    print(10*min(x,y) + max(x,y))
    
