#include <bits/stdc++.h>
using namespace std;
int a[200005];
vector<int> v;
vector<int> g[200005];
int in[200005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  v.clear();
  for (int i = 0; i < 2e5 + 5; i++) g[i].clear(), in[i] = i;
  int n, m;
  cin >> n >> m;
  int i, j;
  for (i = 1; i <= m; i++) cin >> a[i];
  v.push_back(a[1]);
  for (i = 2; i <= m; i++)
    if (a[i] != a[i - 1]) v.push_back(a[i]);
  long long s = 0;
  for (i = 0; i < v.size(); i++) {
    if (i > 0) s += abs(v[i] - v[i - 1]);
    g[v[i]].push_back(i);
  }
  cout << s << " ";
  for (i = 2; i <= n; i++) {
    int x = i - 1;
    int y = i;
    for (j = 0; j < g[x].size(); j++) {
      int u = g[x][j];
      if (u > 0) s -= abs(in[v[u]] - in[v[u - 1]]);
      if (u + 1 < v.size()) s -= abs(in[v[u]] - in[v[u + 1]]);
    }
    for (j = 0; j < g[y].size(); j++) {
      int u = g[y][j];
      if (u > 0) s -= abs(in[v[u]] - in[v[u - 1]]);
      if (u + 1 < v.size()) s -= abs(in[v[u]] - in[v[u + 1]]);
    }
    in[y] = 1;
    in[x] = i;
    for (j = 0; j < g[x].size(); j++) {
      int u = g[x][j];
      if (u > 0) s += abs(in[v[u]] - in[v[u - 1]]);
      if (u + 1 < v.size()) s += abs(in[v[u]] - in[v[u + 1]]);
    }
    for (j = 0; j < g[y].size(); j++) {
      int u = g[y][j];
      if (u > 0) s += abs(in[v[u]] - in[v[u - 1]]);
      if (u + 1 < v.size()) s += abs(in[v[u]] - in[v[u + 1]]);
    }
    cout << s << " ";
  }
  return 0;
}
