n, m = map(int,  input().split())
a = set()
b = set()
mino = float('inf')
for i in map(int, input().split()):
    a.add(i)
for i in map(int, input().split()):
    if (i in a) and i < mino:
        mino = i
    b.add(i)

if mino == float('inf'):
    ma = min(a)
    mb = min(b)
    f = min(ma, mb)
    s = max(ma, mb)
    print (str(f) + str(s))
else:
    print(mino)
    
