import std; void main () { int N, M; readln.read(N, M); auto A = readln.split.to!(int[]); auto dp = new int[][](M + 1, N + 1); int[] ans; BinaryHeap!(Tuple!(int, int)[], "b[1] < a[1]") PQ = []; foreach (bob; 2..N+1) { foreach (d; dp) d[] = int.max; for (int i = 0; bob + i <= N; i++) dp[0][bob + i] = i; for (int i = 0; 1 <= bob - i; i++) dp[0][bob - i] = i; foreach (i; 0..M) { dp[i + 1][] = dp[i][]; // 操作 dp[i + 1][A[i] + 1] = dp[i][A[i]]; dp[i + 1][A[i]] = dp[i][A[i] + 1]; // 右となり int mn = N; for (int j = 0; j < M; j++) { dp[i + 1][j] = min(dp[i + 1][j], mn); mn = min(mn, dp[i + 1][j]); mn++; } // 左となり mn = N; for (int j = M - 1; j >= 0; j--) { dp[i + 1][j] = min(dp[i + 1][j], mn); mn = min(mn, dp[i + 1][j]); mn++; } } ans ~= dp[M][1]; } foreach (i, a; ans) { write(a, i == ans.length - 1 ? '\n' : ' '); } } void read (T...) (string S, ref T args) { import std.conv : to; import std.array : split; auto buf = S.split; foreach (i, ref arg; args) { arg = buf[i].to!(typeof(arg)); } }