n,m=map(int,input().split()) a=list(map(int,input().split())) p=list(range(n)) e=[[n]*n for i in range(n)] for i in range(n): for j in range(n): e[p[i]][p[j]]=min(e[p[i]][p[j]],abs(i-j)) for y in a: p[y-1],p[y]=p[y],p[y-1] for i in range(n): for j in range(n): e[p[i]][p[j]]=min(e[p[i]][p[j]],abs(i-j)) 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[0]] for i in range(1,n)])