#include <bits/stdc++.h>
using namespace std;
vector<int> v[200005];
int arr[200005];
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i < m + 1; i++) {
    cin >> arr[i];
    v[arr[i]].push_back(i);
  }
  arr[0] = arr[1];
  arr[m + 1] = arr[m];
  long long sum = 0;
  for (int i = 1; i < m + 1; i++) {
    sum += abs(arr[i] - arr[i - 1]);
  }
  cout << sum << " ";
  for (int t = 2; t < n + 1; t++) {
    for (int i = 0; i < v[t].size(); i++) {
      int pos = v[t][i];
      if (pos != 1) {
        sum -= abs(arr[pos] - arr[pos - 1]);
        sum += abs(1 - arr[pos - 1]);
      }
      if (pos != m) {
        sum -= abs(arr[pos] - arr[pos + 1]);
        sum += abs(1 - arr[pos + 1]);
      }
      arr[pos] = 1;
    }
    for (int i = 0; i < v[t - 1].size(); i++) {
      int pos = v[t - 1][i];
      if (pos != 1) {
        sum -= abs(arr[pos] - arr[pos - 1]);
        sum += abs(t - arr[pos - 1]);
      }
      if (pos != m) {
        sum -= abs(arr[pos] - arr[pos + 1]);
        sum += abs(t - arr[pos + 1]);
      }
      arr[pos] = t;
    }
    cout << sum << " ";
  }
  puts("");
  return 0;
}
