#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
long long a[maxn];
vector<long long> q[maxn];
long long sum[maxn];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) sum[i] = i;
  long long ans = 0;
  for (int i = 1; i < m; i++) {
    if (a[i] > a[i + 1])
      ans += a[i] - a[i + 1];
    else
      ans += a[i + 1] - a[i];
    if (a[i] == a[i + 1]) continue;
    q[a[i + 1]].push_back(a[i]);
    q[a[i]].push_back(a[i + 1]);
  }
  cout << ans << " ";
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < q[i].size(); j++) ans -= abs(sum[q[i][j]] - i);
    for (int j = 0; j < q[i - 1].size(); j++) ans -= abs(sum[q[i - 1][j]] - 1);
    sum[i - 1] = i, sum[i] = 1;
    for (int j = 0; j < q[i].size(); j++) ans += abs(sum[q[i][j]] - 1);
    for (int j = 0; j < q[i - 1].size(); j++) ans += abs(sum[q[i - 1][j]] - i);
    cout << ans << " ";
  }
  return 0;
}
