n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
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))
elif x not in b and y in a:
    if len(a) > 1 and len(b) > 1:
        a.pop(a.index(y))
        b.pop(b.index(y))
        y = min(b)
        if x < y:
            print(str(x)+str(y))
        else:
            print(str(y)+str(x))
    else:
        print(1)
elif x in b and y not in a:
    if len(a) > 1 and len(b) > 1:
        b.pop(b.index(x))
        a.pop(a.index(x))
        x = min(a)
        if x < y:
            print(str(x)+str(y))
        else:
            print(str(y)+str(x))
    else:
        print(1)
else:
    print(set(a).intersection(b))
