#include <bits/stdc++.h>
using namespace std;
const int QQ = 3e5 + 10;
const int maxN = 3e5 + 100;
const int maxM = 3e5 + 10;
const long long oo = 1e15;
const int module = 1e9 + 7;
const long double du = 1e-9;
void doc() {
  freopen(
      "solve"
      ".inp",
      "r", stdin);
  freopen(
      "solve"
      ".out",
      "w", stdout);
}
int IT[maxN * 4];
void up(int i, int L, int R, int u, int val) {
  if (L > u || R < u) return;
  if (L == R) {
    IT[i] += val;
    return;
  }
  int mid = (L + R) >> 1;
  up(i << 1, L, mid, u, val);
  up(i << 1 | 1, mid + 1, R, u, val);
  IT[i] = IT[i << 1] + IT[i << 1 | 1];
}
int Get(int i, int L, int R, int u, int v) {
  if (L > v || R < u) return 0;
  if (L >= u && R <= v) return IT[i];
  int mid = (L + R) >> 1;
  int Left = Get(i << 1, L, mid, u, v);
  int Right = Get(i << 1 | 1, mid + 1, R, u, v);
  return Left + Right;
}
int Get(int u, int v) {
  if (u == v) return 0;
  int First = abs(u - v);
  int After = v - 1;
  if (v < u) After += 1;
  return After - First;
}
void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> a[n + 1];
  memset(a, 0, sizeof(a));
  int b[m];
  for (int i = 0; i < m; i++) cin >> b[i];
  long long Res = 0;
  for (int i = 0; i < m - 1; i++) {
    int u = b[i];
    int v = b[i + 1];
    Res += abs(u - v);
    a[u].push_back(v);
    a[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    long long TMP = Res;
    TMP -= Get(1, 1, n, i + 1, n);
    for (int v : a[i]) {
      TMP += Get(i, v);
      if (i < v) up(1, 1, n, v, 1);
    }
    cout << TMP << ' ';
  }
}
int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  cout.tie(nullptr);
  solve();
}
