input()
v_1 = input()
v_2 = input()
v_1 = v_1.split()
v_2 = v_2.split()
v_1.sort()
v_2.sort()
for i in v_1 :
    if i in v_2 :
        print(i)
        raise SystemExit
a = v_1[0]
c = v_2[0]
print(min(a,c)+max(a,c))
