#include using namespace std; template istream& operator >> (istream& is, vector& vec) { for(T& x : vec) is >> x; return is; } template ostream& operator << (ostream& os, const vector& vec) { if(vec.empty()) return os; os << vec[0]; for(auto it = vec.begin(); ++it != vec.end(); ) os << ' ' << *it; return os; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector> dp(n, vector(n, 1 << 30)); vector a(m); cin >> a; for(auto &&v : a) v--; for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ dp[i][j] = abs(i - j); } } for(int i = 0; i < m; i++){ vector> ndp(n, vector(n, 1 << 30)); int u = a[i], v = a[i] + 1; for(int j = 0; j < n; j++){ for(int k = 0; k < n; k++){ if(k == u || k == v){ ndp[j][k ^ u ^ v] = min(ndp[j][k ^ u ^ v], dp[j][k]); }else{ ndp[j][k] = min(ndp[j][k], dp[j][k]); } } for(int k = 0; k + 1 < n; k++){ ndp[j][k + 1] = min(ndp[j][k + 1], ndp[j][k] + 1); } for(int k = n - 1; k >= 1; k--){ ndp[j][k - 1] = min(ndp[j][k - 1], ndp[j][k] + 1); } } swap(dp, ndp); } for(int i = 1; i < n; i++){ cout << dp[i][0] << (i + 1 == n ? '\n' : ' '); } }