n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
x = min(a)
y = min(b)
if x not in b and y not in a:
    if x < y:
        print(str(x)+str(y))
    else:
        print(str(y)+str(x))
else:
    if len(a) > 1 and len(b) > 1 and a != b:
        c = set(a).intersection(b)
        for i in c:
            a.pop(a.index(i))
            b.pop(b.index(i))
        if len(a) == 0:
            if min(b) < x:
                print(min(b))
            else:
                print(x)
        elif len(b) == 0:
            if min(a) < y:
                print(min(a))
            else:
                print(y)
        else:
            x = min(a)
            y = min(b)        
            if x < y:
                print(str(x)+str(y))
            else:
                print(str(y)+str(x))        
    else:
        print(min(set(a).intersection(b)))
