N,M=map(int,input().split()) A=list(map(int,input().split())) for i in range(M): A[i]-=1 dp=[[10**10]*N for i in range(M+1)] for j in range(N): dp[M][j]=j for i in range(M,0,-1): for j in range(N): for k in range(N): if j==A[i-1]: continue if k<=j: if k<=A[i-1]<=j: cost1=j-k-1 else: cost1=j-k else: cost1=10**10 if j<=k: if j<=A[i-1]<=k: cost2=k-j-1 else: cost2=k-j else: cost2=10**10 dp[i-1][j]=min(dp[i-1][j],dp[i][k]+min(cost1,cost2)) result=[] for i in range(1,N): result.append(dp[0][i]) print(*result)