#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    s = (s << 3) + (s << 1) + (ch ^ 48);
    ch = getchar();
  }
  return s * w;
}
const long long mod = 998244353;
const int N = 1001000;
int n, m;
int a[N];
vector<int> Q[N];
long long result[N];
int id[N];
int now;
int pos(int x) {
  if (x == now) return 1;
  if (x < now) return x + 1;
  return x;
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; i++) id[i] = i;
  long long s = 0;
  for (int i = 1; i <= m; i++) {
    a[i] = read();
    Q[a[i]].push_back(i);
    if (i != 1) s += abs(a[i] - a[i - 1]);
  }
  result[1] = s;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < Q[i].size(); j++) {
      int x = Q[i][j];
      if (x > 1) s -= abs(pos(a[x]) - pos(a[x - 1]));
      if (x < m) s -= abs(pos(a[x + 1]) - pos(a[x]));
    }
    for (int j = 0; j < Q[i - 1].size(); j++) {
      int x = Q[i - 1][j];
      if (x > 1) s -= abs(pos(a[x]) - pos(a[x - 1]));
      if (x < m) s -= abs(pos(a[x + 1]) - pos(a[x]));
    }
    now = i;
    for (int j = 0; j < Q[i].size(); j++) {
      int x = Q[i][j];
      if (x > 1) s += abs(pos(a[x]) - pos(a[x - 1]));
      if (x < m) s += abs(pos(a[x + 1]) - pos(a[x]));
    }
    for (int j = 0; j < Q[i - 1].size(); j++) {
      int x = Q[i - 1][j];
      if (x > 1) s += abs(pos(a[x]) - pos(a[x - 1]));
      if (x < m) s += abs(pos(a[x + 1]) - pos(a[x]));
    }
    result[i] = s;
  }
  for (int i = 1; i <= n; i++) printf("%lld ", result[i]);
  printf("\n");
}
