#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 1;
const int base = 1e9 + 7;
template <typename T>
void Read(T &x) {
  bool Neg = false;
  char c;
  for (c = getchar(); c < '0' || c > '9'; c = getchar())
    if (c == '-') Neg = !Neg;
  x = c - '0';
  for (c = getchar(); c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
  if (Neg && x > 0) x = -x;
}
long long power(long long a, long long t) {
  if (t == 1) return a;
  long long c = power(a, t / 2);
  if (t % 2 == 1)
    return ((c * c) % base * a) % base;
  else
    return (c * c) % base;
}
int n, m;
long long a[maxn];
vector<long long> dd[maxn];
long long place[maxn];
long long chk(set<int> s, int i) {
  long long ans = 0;
  for (auto v : s) {
    long long x = a[v], y = a[v + 1];
    if (x < i)
      x++;
    else if (x == i)
      x = 1;
    if (y < i)
      y++;
    else if (y == i)
      y = 1;
    ans += abs(x - y);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> a[i];
    dd[a[i]].push_back(i);
  }
  long long sum = 0;
  for (int i = 1; i <= m - 1; i++) {
    sum += abs(a[i] - a[i + 1]);
  }
  cout << sum << " ";
  for (int i = 2; i <= n; i++) {
    set<int> s;
    for (auto &v : dd[i - 1]) {
      if (v - 1 >= 1) s.insert(v - 1);
      if (v + 1 <= m) s.insert(v);
    }
    for (auto &v : dd[i]) {
      if (v - 1 >= 1) s.insert(v - 1);
      if (v + 1 <= m) s.insert(v);
    }
    sum -= chk(s, i - 1);
    sum += chk(s, i);
    cout << sum << " ";
  }
}
