p,n=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
minx=min(x)
miny=min(y)
if minx==miny:
    print(minx)
    exit()
else:
    for i in range(p):
        if x[i]in y:
            print(x[i])
            exit()

h=list()
h.append(minx)
h.append(miny)
h=sorted(h)
print((h[0]*10)+h[1])