n = input()
n_list = [int(i) for i in input().split()]
m_list = [int(i) for i in input().split()]

    
mins = []
mins.append(min(n_list))
mins.append(min(m_list))
mins.sort()
if mins[0] == mins[1]:
    print(mins[0])
elif mins[0] != 0:
    print(mins[0]*10+mins[1])
else:
    print(mins[1]*10+mins[0])