#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN = 2e5 + 5;
int n, m, x[MAXN];
vector<int> iuque[MAXN];
int calc(int i, int a, int b) {
  if (a < 1 || b > m) return 0;
  a = x[a];
  b = x[b];
  if ((a < i && b < i) || (a > i && b > i))
    return abs(a - b);
  else if (a == i || b == i) {
    if (a == b)
      return 0;
    else {
      if (a == i) a = b;
      return (a < i) ? a : (a - 1);
    }
  } else
    return abs(a - b) - 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int j = 1; j <= m; ++j) cin >> x[j], iuque[x[j]].emplace_back(j);
  ll res = 0;
  for (int j = 1; j < m; ++j) res += (ll)calc(1, j, j + 1);
  cout << res << " ";
  for (int i = 2; i <= n; ++i) {
    for (int h : iuque[i - 1]) {
      res -= (ll)calc(i - 1, h - 1, h);
      res -= (ll)calc(i - 1, h, h + 1);
      res += (ll)calc(i, h - 1, h);
      res += (ll)calc(i, h, h + 1);
    }
    for (int h : iuque[i]) {
      res -= (ll)calc(i - 1, h - 1, h);
      res -= (ll)calc(i - 1, h, h + 1);
      res += (ll)calc(i, h - 1, h);
      res += (ll)calc(i, h, h + 1);
    }
    cout << res << " ";
  }
  return 0;
}
