#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}
using ll = long long;
const ll mod = 1e9 + 7;
const int maxn = 1e6 + 5;
int n, m;
ll x[maxn];
map<int, vector<int>> ind;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> x[i];
    ind[x[i]].push_back(i);
  }
  ll norm = 0;
  for (int i = 1; i <= m - 1; i++) {
    norm += abs(x[i] - x[i + 1]);
  }
  cout << norm << " ";
  multiset<int> open, close;
  for (int i = 1; i < m; i++) {
    int a = x[i];
    int b = x[i + 1];
    if (a > b) swap(a, b);
    if (a == b) {
      continue;
    }
    open.insert(a);
    close.insert(b);
  }
  while (!open.empty() && *open.begin() == 1) {
    norm--;
    open.erase(open.begin());
  }
  while (!close.empty() && *close.begin() == 1) {
    norm++;
    close.erase(close.begin());
  }
  for (int i = 2; i <= n; i++) {
    while (!close.empty() && *close.begin() == i) {
      norm++;
      close.erase(close.begin());
    }
    ll cur = norm;
    auto invert = [&](int i, int other) {
      if (other < i) {
        cur -= (i - other);
        cur += i - (i - other);
      }
      if (other > i) {
        cur += i - 1;
      }
    };
    for (int idx : ind[i]) {
      if (idx > 1 && x[idx - 1] != i) {
        invert(i, x[idx - 1]);
      }
      if (idx < m && x[idx + 1] != i) {
        invert(i, x[idx + 1]);
      }
    }
    cout << cur << " ";
    while (!open.empty() && *open.begin() == i) {
      norm--;
      open.erase(open.begin());
    }
  }
  cout << endl;
  return 0;
}
