#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
long long pref[N];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  long long x[m];
  for (long long i = 0; i < m; i++) {
    cin >> x[i];
  }
  vector<long long> side[n + 1];
  long long f1 = 0;
  for (long long i = 0; i < m - 1; i++) {
    long long u = x[i], v = x[i + 1];
    f1 += abs(u - v);
    if (u != v) {
      side[u].push_back(v);
      side[v].push_back(u);
    }
    if (u > v) swap(u, v);
    if (abs(u - v) <= 1) continue;
    long long l = u + 1, r = v - 1;
    pref[l]++;
    pref[r + 1]--;
  }
  for (long long i = 1; i <= n; i++) {
    pref[i] += pref[i - 1];
  }
  cout << f1 << " ";
  for (long long i = 2; i <= n; i++) {
    long long cur = f1 - pref[i];
    for (auto x : side[i]) {
      cur -= abs(x - i);
      cur += x - 1;
      if (x < i) cur++;
    }
    cout << cur << " ";
  }
  return 0;
}
