#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 3e5 + 7;
const long long MOD = 1e9 + 7;
const long long MOD1 = 1e9 + 9;
const long long INF = 2e9 + 9;
const long double EPS = 1e-8;
void solve();
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long q = 1;
  if (0) cin >> q;
  while (q--) solve();
}
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<long long> v(m);
  for (long long &i : v) {
    cin >> i;
    --i;
  }
  vector<long long> res(n);
  for (long long i = 0; i < m - 1; ++i) res[0] += abs(v[i] - v[i + 1]);
  vector<long long> cnt(n);
  vector<vector<long long>> adj(n);
  for (long long i = 0; i < m - 1; ++i) {
    long long l = v[i], r = v[i + 1];
    if (l != r) {
      adj[l].push_back(r);
      adj[r].push_back(l);
    }
    if (l > r) swap(l, r);
    if (r - l >= 2) {
      ++cnt[l + 1];
      --cnt[r];
    }
  }
  for (long long i = 0; i < n - 1; ++i) cnt[i + 1] += cnt[i];
  for (long long i = 1; i < n; ++i) {
    res[i] = res[0] - cnt[i];
    for (long long j : adj[i]) {
      res[i] -= abs(i - j);
      res[i] += j + (j < i);
    }
  }
  for (long long i : res) cout << i << ' ';
}
