#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  ios::sync_with_stdio(false), cin.tie(), cout.tie();
  int n, m;
  cin >> n >> m;
  vector<int> x(m);
  for (int i = 0; i < m; i++) cin >> x[i], x[i]--;
  vector<long long> res(n, 0);
  for (int i = 0; i < m - 1; i++) {
    res[0] += abs(x[i] - x[i + 1]);
  }
  vector<int> cnt(n, 0);
  vector<vector<int>> adj(n);
  for (int i = 0; i < m - 1; i++) {
    int l = x[i], r = x[i + 1];
    if (l != r) {
      adj[l].push_back(r);
      adj[r].push_back(l);
    }
    if (l > r) swap(l, r);
    if (r - l < 2) continue;
    cnt[l + 1]++;
    cnt[r]--;
  }
  for (int i = 1; i < n; i++) cnt[i] += cnt[i - 1];
  for (int i = 1; i < n; i++) {
    res[i] = res[0] - cnt[i];
    for (auto j : adj[i]) {
      res[i] -= abs(i - j);
      res[i] += j + (j < i);
    }
  }
  for (int i = 0; i < n; i++) cout << res[i] << " ";
}
