n,m=map(int,input().split()) a=list(map(int,input().split())) p=list(range(n)) e=[n]*n*n for y in range(n*n): i,j=y//n,y%n e[p[i]*n+p[j]]=min(e[p[i]*n+p[j]],abs(i-j)) for v in a: p[v-1],p[v]=p[v],p[v-1] for y in range(n*n): i,j=y//n,y%n e[p[i]*n+p[j]]=min(e[p[i]*n+p[j]],abs(i-j)) for k in range(n): for y in range(n*n): i,j=y//n,y%n e[y]=min(e[y],e[i*n+k]+e[k*n+j]) print(*[e[i*n+p[0]] for i in range(1,n)])