def list_intersection(l1, l2):
    out = []
    for i1 in l1:
        for i2 in l2:
            if i1 == i2:
                out.append(i1)

    out.sort()
    return out

n, m = [int(i) for i in input().split()]

a_s = [int(i) for i in input().split()]
a_s.sort()
a = a_s[0]

b_s = [int(i) for i in input().split()]
b_s.sort()
b = b_s[0]

if a == b:
    print(a)

else:
    intersection = list_intersection(a_s, b_s)
    if intersection != []:
        print(intersection[0])
    
    elif a > b:
        print(str(b)+str(a))
    elif a < b:
        print(str(a)+str(b))
