#include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N,M; cin >> N >> M; vector A(M); for(auto &a : A) cin >> a; reverse(A.begin(),A.end()); int inf = 1e9; vector> dp(M+1,vector(N+2,inf)); dp.at(0).at(1) = 0; auto chmin = [](auto &a, auto b){a = min(a,b);}; for(int i=0; i<=M; i++){ for(int k=2; k<=N; k++) chmin(dp.at(i).at(k),dp.at(i).at(k-1)+1); for(int k=N-1; k>=1; k--) chmin(dp.at(i).at(k),dp.at(i).at(k+1)+1); if(i == M) break; int a = A.at(i); for(int k=1; k<=N; k++){ if(k == a) chmin(dp.at(i+1).at(k+1),dp.at(i).at(k)); else if(k == a+1) chmin(dp.at(i+1).at(k-1),dp.at(i).at(k)); else chmin(dp.at(i+1).at(k),dp.at(i).at(k)); } } for(int i=2; i<=N; i++){ if(i != 2) cout << " "; cout << dp.back().at(i); } cout << endl; }