N, M = map(int, input().split()) A = list(map(int, input().split())) P = list(range(N)) for i in range(M): P[A[i]-1], P[A[i]] = P[A[i]], P[A[i]-1] B = P[0] P = list(range(N)) idxB = B MIN = [] for i in range(1, N): MIN.append(abs(B-i)) for i in range(M): P[A[i]-1], P[A[i]] = P[A[i]], P[A[i]-1] if P[A[i]-1] == B: idxB = A[i]-1 elif P[A[i]] == B: idxB = A[i] for j in range(N): if P[j] >= 1: MIN[P[j]-1] = min(MIN[P[j]-1], abs(idxB-j)) print(*MIN)