input()
a = [int (i) for i in input().split()]
b = [int (i) for i in input().split()]


lst = list()

for a_ in a:
    for b_ in b:
        if a_ == b_:
            lst.append(a_)

if len(lst) != 0:
    print(min(lst))
else:
    bb = min(b)
    aa = min(a)
    if aa < bb:
        print(str(aa)+str(bb))
    elif bb < aa:
        print(str(bb)+str(aa))
