#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n, m;
int x[maxn];
vector<pair<int, int> > ps;
int cnt[maxn];
int cs[maxn];
vector<int> G[maxn];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d", &x[i]);
  }
  long long ans = 0;
  for (int i = 1; i < m; i++) {
    int u = x[i], v = x[i + 1];
    if (u == v) continue;
    if (u > v) swap(u, v);
    ans += v - u;
    cnt[u]++;
    ps.push_back(make_pair(u, -1));
    ps.push_back(make_pair(v, 1));
    G[u].push_back(v);
    G[v].push_back(u);
  }
  sort(ps.begin(), ps.end());
  int j = 0, f = 0;
  for (int i = 1; i <= n; i++) {
    while (j < ps.size() && ps[j].first <= i && ps[j].second < 0) {
      f += ps[j].second;
      j++;
    }
    cs[i] = -f;
    while (j < ps.size() && ps[j].first <= i && ps[j].second > 0) {
      f += ps[j].second;
      j++;
    }
  }
  printf("%lld ", ans);
  for (int i = 2; i <= n; i++) {
    long long tmp = ans;
    for (auto u : G[i]) {
      if (u < i) {
        tmp -= i - u;
        tmp += u;
      } else {
        tmp -= u - i;
        tmp += u - 1;
      }
    }
    tmp -= cs[i] - G[i].size();
    printf("%lld ", tmp);
  }
  return 0;
}
