n,m=map(int,input().split()) a=list(map(int,input().split())) p=[list(range(n))] for i in range(m): y=a[i]-1 p+=[p[-1].copy()] p[-1][y],p[-1][y+1]=p[-1][y+1],p[-1][y] e=[[n]*n for i in range(n)] for i in range(len(p)): for j in range(n): for k in range(n): e[p[i][j]][p[i][k]]=min(e[p[i][j]][p[i][k]],abs(j-k)) for k in range(n): for i in range(n): for j in range(n): e[i][j]=min(e[i][j],e[i][k]+e[k][j]) print(*[e[i][p[-1][0]] for i in range(1,n)])