input()
v_1 = input()
v_2 = input()
v_1 = v_1.split()
v_2 = v_2.split()
v_1.sort()
v_2.sort()

v = set(v_1) & set(v_2)
if len(v) > 0 :
    print(min(v))
    raise SystemExit

a = min(v_1)
c = min(v_2)
print(min(a,c)+max(a,c))
