import java.util.ArrayDeque; import java.util.Arrays; import java.util.Deque; import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int[] a = new int[m]; for (int i = 0; i < m; i++) { a[i] = sc.nextInt() - 1; } sc.close(); int inf = 100000000; StringBuilder sb = new StringBuilder(); for (int i = 1; i < n; i++) { int[][] d = new int[m + 1][n]; for (int j = 0; j < d.length; j++) { Arrays.fill(d[j], inf); } d[0][i] = 0; Deque que = new ArrayDeque<>(); que.add(new Obj(0, i, 0)); while (!que.isEmpty()) { Obj o = que.poll(); if (o.x == m && o.y == 0) { sb.append(o.d).append(' '); break; } if (o.x < m) { if (a[o.x] == o.y) { if (o.d < d[o.x + 1][o.y + 1]) { d[o.x + 1][o.y + 1] = o.d; que.addFirst(new Obj(o.x + 1, o.y + 1, o.d)); } } else if (a[o.x] == o.y - 1) { if (o.d < d[o.x + 1][o.y - 1]) { d[o.x + 1][o.y - 1] = o.d; que.addFirst(new Obj(o.x + 1, o.y - 1, o.d)); } } else { d[o.x + 1][o.y] = o.d; que.addFirst(new Obj(o.x + 1, o.y, o.d)); } } if (o.y < n - 1 && o.d + 1 < d[o.x][o.y + 1]) { d[o.x][o.y + 1] = o.d + 1; que.addLast(new Obj(o.x, o.y + 1, o.d + 1)); } if (o.y > 0 && o.d + 1 < d[o.x][o.y - 1]) { d[o.x][o.y - 1] = o.d + 1; que.addLast(new Obj(o.x, o.y - 1, o.d + 1)); } } // for (int j = 0; j < d.length; j++) { // System.out.println(Arrays.toString(d[i])); // } // System.out.println(); } sb.deleteCharAt(sb.length() - 1); System.out.println(sb.toString()); } static class Obj { int x, y, d; public Obj(int x, int y, int d) { this.x = x; this.y = y; this.d = d; } } }