n,m = map(int,input().split())
s1 = set(map(int,input().split()))
s2 = set(map(int,input().split()))
if s1&s2:
    print(min(s1&s2))
else:
    c1 = min(s1)
    c2 = min(s2)
    if c1<c2:
        print(c1*10+c2)
    else:
        print(c2*10+c1)