#include using namespace std; using ll = long long; const ll LINF = (ll)1e18 + 7; template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } return false; } int main() { ll n, m; cin >> n >> m; vector a(m); for (ll i = 0; i < m; i++) { cin >> a[i]; a[i]--; } // present[i][j] := i回目のプレゼントのswapの後で椅子jにあるプレゼントの番号、0-indexed vector present(m + 1, vector(n)); // 初期状態 for (ll i = 0; i < n; i++) { present[0][i] = i; } // プレイリストのswap for (ll i = 0; i < m; i++) { present[i + 1] = present[i]; swap(present[i + 1][a[i]], present[i + 1][a[i] + 1]); } // s[i] := 初期状態のあみだくじで、最終的に椅子iに渡るプレゼントの番号、0-indexed vector s = present[m]; // min_swap_to_s0[i] := s[0]とs[i]とを一気にスワップする最短回数 vector min_swap_to_s0(n, LINF); min_swap_to_s0[s[0]] = 0; // i回目のswap後に、各 0 < j < n に対して、s[0]とs[j]とを一気にスワップする最短回数を求める for (ll i = 0; i <= m; i++) { ll present_s0 = 0; // s[0]の位置を探す for (ll j = 0; j < n; j++) { if (present[i][j] == s[0]) { present_s0 = j; } } // s[0]とs[j]の最短swap回数を求める for (ll j = 0; j < n; j++) { ll present_num = present[i][j]; if (present_s0 == present_num) continue; chmin(min_swap_to_s0[present_num], abs(present_s0 - present_num)); } } for (ll i = 1; i < (ll)min_swap_to_s0.size(); i++) { cout << min_swap_to_s0[i] << (i == (ll)min_swap_to_s0.size() - 1 ? "\n" : " "); } }