#include using namespace std; //#include //using namespace atcoder; //using mint = modint998244353; //多倍長整数// //#include //namespace mp = boost::multiprecision; //using Bint = mp::cpp_int; const int INF = 1e9; const int MOD = 998244353; const long long LINF = 4e18; using ll = long long; using vi = vector; using vl = vector; using vs = vector; using vc = vector; using vb = vector; using vvi = vector>; using vvvi = vector>>; using vvvvi = vector>>>; using vvl = vector>; using vvvl = vector>>; using vvvvl = vector>>>; using vvc = vector>; using vvb = vector>; using vvvb = vector>>; using vvvvb = vector>>>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define dump(x) cout << #x << " = " << (x) << endl; #define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl #define ALL(obj) (obj).begin(),(obj).end() int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n,m; cin >> n >> m; vi a(m); rep(i,m) cin >> a[i]; rep(i,m) a[i]--; vvi b(n,vi(m + 1)); vi cur(n); iota(ALL(cur),0); rep(i,n) b[i][0] = i; rep(i,m){ swap(cur[a[i]],cur[a[i] + 1]); rep(j,n) b[cur[j]][i + 1] = j; } rep(i,n){ for(int j = m - 1;j >= 0;j--){ b[i][j] = min(b[i][j],b[i][j + 1]); } } vi dp(n,INF); vi pos(n); iota(ALL(pos),0); for(int i = 1;i < n;i++){ rep(j,n){ dp[i] = min(dp[i],abs(pos[i] - pos[j]) + b[j][0]); } } //rep(i,n) cout << pos[i] + 1 << ' '; rep(i,m){ int pos1 = -1;int pos2 = -1; rep(j,n){ if(pos[j] == a[i]) pos1 = j; if(pos[j] == a[i] + 1) pos2 = j; } swap(pos[pos1],pos[pos2]); rep(i,n) cout << pos[i] + 1 << ' '; cout << endl; for(int j = 1;j < n;j++){ rep(k,n){ dp[j] = min(dp[j],abs(pos[j] - pos[k]) + b[k][i + 1]); } } } for(int i = 1;i < n;i++) cout << dp[i] << ' '; return 0; }