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 j in range(n): e[p[v-1]*n+p[j]]=min(e[p[v-1]*n+p[j]],abs(v-1-j)) e[p[j]*n+p[v-1]]=min(e[p[j]*n+p[v-1]],abs(v-1-j)) e[p[v]*n+p[j]]=min(e[p[v]*n+p[j]],abs(v-j)) e[p[j]*n+p[v]]=min(e[p[j]*n+p[v]],abs(v-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)])