#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
int val[maxn];
vector<int> vec[maxn];
int vis[maxn];
long long int sum[maxn], sumt[maxn];
int get(int id) {
  int l = 0, r = vec[id].size();
  if (!r) return 0;
  if (vec[id][0] >= id) return 0;
  for (int i = 0; i < 20; i++) {
    int mid = (l + r) / 2;
    if (vec[id][mid] < id)
      l = mid;
    else
      r = mid;
  }
  return l + 1;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) cin >> val[i];
  long long int ans = 0;
  for (int i = 1; i <= m - 1; i++) {
    int l = val[i], r = val[i + 1];
    vec[l].push_back(r);
    vec[r].push_back(l);
    if (r == l) continue;
    ans += abs((r - l));
    sum[l] += r - 1;
    sum[r] += l - 1;
    sumt[l] += abs(r - l);
    sumt[r] += abs(r - l);
    if (r == l) continue;
    if (l > r) {
      vis[r + 1]++, vis[l]--;
    } else
      vis[l + 1]++, vis[r]--;
  }
  for (int i = 1; i <= n; i++) {
    sort(vec[i].begin(), vec[i].end());
  }
  cout << ans << endl;
  long long int tmp = 0;
  tmp += vis[1];
  for (int i = 2; i <= n; i++) {
    tmp += vis[i];
    long long int tans = ans;
    tans -= tmp;
    tans -= sumt[i];
    tans += sum[i];
    int l = 0, r = vec[i].size();
    int id = get(i);
    tans += id;
    cout << tans << endl;
  }
  return 0;
}
