n,m=map(int,input().split()) a=list(map(int,input().split())) p=list(range(n)) for v in a: p[v-1],p[v]=p[v],p[v-1] q=[n]*n for i in range(n): q[p[i]]=i for v in a[::-1]: p[v-1],p[v]=p[v],p[v-1] for i in range(n): for j in range(n): q[i]=min(q[i],q[j]+abs(i-j)) print(*q[1:])