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] for i in range(N): for j in range(N): ANS[j]=min(ANS[j],ANS[i]+abs(i-j)) print(*ANS[1:])