#include using namespace std; struct Edge{ int ton,tom,cost; }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n,m; cin >> n >> m; vector A(m); for (auto &a: A) cin >> a; const int INF = 1e9; vector>> e(m+1,vector>(n)); for (int i = 0; i < m+1; i++){ int a = A[i]; a--; for (int j = 0; j < n; j++){ if (i < m){ if (j == a){ e[i+1][j+1].push_back({i,j,0}); e[i+1][j].push_back({i,j+1,0}); } else{ e[i+1][j].push_back({i,j,0}); } } if (j < n-1){ e[i][j].push_back({i,j+1,1}); e[i][j+1].push_back({i,j,1}); } } } vector> dist(m+1,vector(n,INF)); dist[m][0] = 0; using pos = pair>; priority_queue,greater> h; h.push({0,{m,0}}); while (!h.empty()){ pos now = h.top(); h.pop(); int x = now.second.first; int y = now.second.second; int d = now.first; if (dist[x][y] != d) continue; for (auto& nex: e[x][y]){ int nx = nex.ton; int ny = nex.tom; int nd = d + nex.cost; if (dist[nx][ny] > nd){ dist[nx][ny] = nd; h.push({nd,{nx,ny}}); } } } for (int i = 1; i < n; i++){ cout << dist[0][i] << " "; } cout << endl; return 0; }