from collections import deque N, M = map(int, input().split()) A = list(map(int, input().split())) vertex = (M+1)*N G = [[] for _ in range(vertex)] for i in range(M+1): for j in range(N-1): G[i*N+j].append((i*N+j+1, 1)) G[i*N+j+1].append((i*N+j, 1)) for i in range(M): for j in range(N): G[i*N+j].append(((i+1)*N+j, 0)) idx = M-1-i G[i*N+A[idx]-1].append(((i+1)*N+A[idx], 0)) G[i*N+A[idx]].append(((i+1)*N+A[idx]-1, 0)) INF = 10**18 visited = [INF]*vertex visited[0] = 0 que = deque() que.append(0) while que: n = que.popleft() for v, c in G[n]: if visited[n]+c < visited[v]: visited[v] = visited[n]+c if c == 0: que.appendleft(v) else: que.append(v) print(*visited[-(N-1):])