#include using namespace std; using ll = long long; template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } return false; } // 計算量O(NM) int main() { ll n, m; cin >> n >> m; vector a(m); for (ll i = 0; i < m; i++) { cin >> a[i]; a[i]--; // 0-indexedにする } vector dist_from_chair0(n); for (ll i = 0; i < n; i++) { dist_from_chair0[i] = i; } for (ll i = m - 1; i >= 0; i--) { swap(dist_from_chair0[a[i]], dist_from_chair0[a[i] + 1]); for (ll j = 0; j < n; j++) { if (j + 1 < n) chmin(dist_from_chair0[j + 1], dist_from_chair0[j] + 1); } for (ll j = n - 1; j >= 0; j--) { if (j - 1 >= 0) chmin(dist_from_chair0[j - 1], dist_from_chair0[j] + 1); } } for (ll i = 1; i < (ll)dist_from_chair0.size(); i++) { cout << dist_from_chair0[i] << (i == (ll)dist_from_chair0.size() - 1 ? "\n" : " "); } }