#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using ll = long long;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<int> x(m);
  vector<vector<int>> x_ind(n);
  for (int i = 0; i < m; ++i) {
    cin >> x[i];
    --x[i];
    x_ind[x[i]].push_back(i);
  }
  vector<int> pos(n), pos_x(m);
  iota(pos.begin(), pos.end(), 0);
  for (int i = 0; i < m; ++i) {
    pos_x[i] = x[i];
  }
  ll ans = 0;
  for (int j = 1; j < m; ++j) {
    ans += abs(pos_x[j - 1] - pos_x[j]);
  }
  for (int i = 0; i < n; ++i) {
    cout << ans << ' ';
    if (i + 1 == n) break;
    swap(pos[i], pos[i + 1]);
    for (int j : x_ind[i]) {
      if (j - 1 >= 0) ans -= abs(pos_x[j - 1] - pos_x[j]);
      if (j + 1 < m) ans -= abs(pos_x[j] - pos_x[j + 1]);
      pos_x[j] = pos[x[j]];
      if (j - 1 >= 0) ans += abs(pos_x[j - 1] - pos_x[j]);
      if (j + 1 < m) ans += abs(pos_x[j] - pos_x[j + 1]);
    }
    for (int j : x_ind[i + 1]) {
      if (j - 1 >= 0) ans -= abs(pos_x[j - 1] - pos_x[j]);
      if (j + 1 < m) ans -= abs(pos_x[j] - pos_x[j + 1]);
      pos_x[j] = pos[x[j]];
      if (j - 1 >= 0) ans += abs(pos_x[j - 1] - pos_x[j]);
      if (j + 1 < m) ans += abs(pos_x[j] - pos_x[j + 1]);
    }
  }
  cout << '\n';
  return 0;
}
