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)
flag = 0
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:
            if len(a) > 1 and len(b) > 1:
                a.pop(a.index(i))
                b.pop(b.index(i))
                flag = 1
            else:
                flag = 0
        if flag == 1:
            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)))
    else:
        print(min(set(a).intersection(b)))
