import sys input = sys.stdin.readline N,M=map(int,input().split()) A=list(map(int,input().split())) L=list(range(N)) for a in A: x=a y=a-1 L[x],L[y]=L[y],L[x] ANS=[1<<60]*N for i in range(N): ANS[L[i]]=i for a in A[::-1]: x=a y=a-1 L[x],L[y]=L[y],L[x] ANS2=ANS[:] for i in range(N): for j in range(N): ANS2[L[j]]=min(ANS2[L[j]],ANS[L[i]]+abs(i-j)) ANS=ANS2 print(*ANS[1:])