
n,m = map(int,raw_input().split())

A = map(int,raw_input().split())
B = map(int,raw_input().split())


def ct(A,B):
    for x in range(1,10):
        if x in A and x in B:
            return x
    a,b = min(A),min(B)
    if a==0:
        return 10*b
    elif b==0:
        return 10*a
    else:
        return min(10*a+b,10*b+a)

print ct(A,B)

