#include <bits/stdc++.h>
using namespace std;
const long long o = 1;
const int maxl = 20;
const int all = o << 20;
const int maxn = 200007;
long long a[maxn << 2];
long long tag[maxn << 2];
inline void push_up(int p) { a[p] = a[p << 1] + a[p << 1 | 1]; }
inline void push_down(int l, int r, int p) {
  int mid = l + r >> 1;
  a[p << 1] += tag[p] * (mid - l + 1);
  a[p << 1 | 1] += tag[p] * (r - mid);
  tag[p << 1] += tag[p];
  tag[p << 1 | 1] += tag[p];
  tag[p] = 0;
}
void modify(int l, int r, int L, int R, int v, int p = 1) {
  if (L <= l && R >= r) {
    a[p] += (r - l + 1) * v;
    tag[p] += v;
    return;
  }
  int mid = l + r >> 1;
  if (tag[p]) push_down(l, r, p);
  if (mid >= L) modify(l, mid, L, R, v, p << 1);
  if (mid < R) modify(mid + 1, r, L, R, v, p << 1 | 1);
  push_up(p);
}
long long qury(int l, int r, int L, int R, int p = 1) {
  if (L <= l && R >= r) return a[p];
  long long ans = 0;
  if (tag[p]) push_down(l, r, p);
  int mid = l + r >> 1;
  if (mid >= L) ans += qury(l, mid, L, R, p << 1);
  if (mid < R) ans += qury(mid + 1, r, L, R, p << 1 | 1);
  return ans;
}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  vector<int> seq(m + 1);
  vector<long long> val(n + 1, 0);
  vector<long long> b(n + 1, 0);
  for (int i = (1); i <= (m); ++i) cin >> seq[i];
  for (int i = (2); i <= (m); ++i) {
    val[seq[i]] += abs(seq[i] - seq[i - 1]);
    if (i != m) {
      val[seq[i]] += abs(seq[i] - seq[i + 1]);
      if (seq[i] > seq[i + 1])
        b[seq[i]] += seq[i + 1];
      else if (seq[i] < seq[i + 1])
        b[seq[i]] += seq[i + 1] - 1;
    }
    int L = seq[i];
    int R = seq[i - 1];
    if (L > R) swap(L, R);
    if (R - L > 1) modify(1, n, L + 1, R - 1, 1);
    if (seq[i] > seq[i - 1])
      b[seq[i]] += seq[i - 1];
    else if (seq[i] < seq[i - 1])
      b[seq[i]] += seq[i - 1] - 1;
  }
  val[seq[1]] += abs(seq[2] - seq[1]);
  if (seq[1] > seq[2])
    b[seq[1]] += seq[2];
  else if (seq[1] < seq[2])
    b[seq[1]] += seq[2] - 1;
  long long ans = 0;
  for (int i = (2); i <= (m); ++i) ans += abs(seq[i] - seq[i - 1]);
  cout << ans;
  for (int p = (2); p <= (n); ++p) {
    long long gx = qury(1, n, p, p);
    long long ta = ans - gx;
    ta -= val[p];
    ta += b[p];
    cout << " " << ta;
  }
  cout << endl;
  return 0;
}
