#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n, m;
int a[maxn];
int p[maxn];
vector<int> pos[maxn];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    p[i] = i;
  }
  for (int i = 1; i <= m; i++) {
    cin >> a[i];
    pos[a[i]].push_back(i);
  }
  long long res = 0;
  for (int i = 1; i <= m - 1; i++) {
    res += abs(a[i] - a[i + 1]);
  }
  printf("%lld ", res);
  for (int i = 2; i <= n; i++) {
    int len = pos[i].size();
    for (int j = 0; j < len; j++) {
      int k = pos[i][j];
      if (k > 1) res -= abs(i - p[a[k - 1]]);
      if (k < m) res -= abs(i - p[a[k + 1]]);
    }
    len = pos[i - 1].size();
    for (int j = 0; j < len; j++) {
      int k = pos[i - 1][j];
      if (k > 1 && a[k - 1] != i) res -= abs(1 - p[a[k - 1]]);
      if (k < m && a[k + 1] != i) res -= abs(1 - p[a[k + 1]]);
    }
    p[i] = 1;
    p[i - 1] = i;
    len = pos[i].size();
    for (int j = 0; j < len; j++) {
      int k = pos[i][j];
      if (k > 1) res += abs(1 - p[a[k - 1]]);
      if (k < m) res += abs(1 - p[a[k + 1]]);
    }
    len = pos[i - 1].size();
    for (int j = 0; j < len; j++) {
      int k = pos[i - 1][j];
      if (k > 1 && a[k - 1] != i) res += abs(i - p[a[k - 1]]);
      if (k < m && a[k + 1] != i) res += abs(i - p[a[k + 1]]);
    }
    printf("%lld ", res);
  }
  return 0;
}
