n,m=map(int,input().split()) a=list(map(int,input().split())) p=list(range(n)) for v in a: p[v-1],p[v]=p[v],p[v-1] q=[n]*n for i in range(n): q[p[i]]=i for v in a[::-1]: p[v-1],p[v]=p[v],p[v-1] nq=q.copy() for i in range(n): for j in range(n): nq[p[i]]=min(nq[p[i]],q[p[j]]+abs(i-j)) q=nq print(*q[1:])