l = raw_input().split(" ")
ns = raw_input().split(" ")
ms = raw_input().split(" ")
n = []
m = []
mins = 10
for an in ns:
    n.append(int(an))
    for am in ms :
        m.append(int(am))
        if an == am :
            if int(an) < mins :
                mins = int(an)
            
mn = min(n)
mm = min(m)
f = str(min([mn,mm])) + str(max([mn,mm]))
if mins == 10 :
    print(f)
else:
    print(mins)