#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int maxm = 2e5 + 10;
const int mod = 998244353;
const long long linf = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const double eps = 1e-6;
int LobN;
inline int lowbit(int x) { return (x & (-x)); }
void add(long long *c, int x, long long v) {
  while (x <= LobN) c[x] += v, x += lowbit(x);
}
long long que(long long *c, int x) {
  long long res = 0;
  while (x) res += c[x], x -= lowbit(x);
  return res;
}
template <typename S, typename T>
inline bool Min(S &a, const T &b) {
  return a > b ? a = b, true : false;
}
template <typename S, typename T>
inline bool Max(S &a, const T &b) {
  return a < b ? a = b, true : false;
}
template <typename S, typename T>
inline void Adm(S &a, const T &b) {
  a = (a + b) % mod;
  if (a < 0) a += mod;
}
template <typename S, typename T>
inline void Mum(S &a, const T &b) {
  a = 1LL * a * b % mod;
}
template <typename T>
inline T Gcd(T a, T b) {
  while (b) {
    T t = b;
    b = a % b;
    a = t;
  }
  return a;
}
template <typename T>
inline int BitCnt(T x) {
  int cnt = 0;
  while (x) ++cnt, x &= x - 1;
  return cnt;
}
template <typename T>
inline bool IsPri(T x) {
  if (x < 2) return false;
  for (T i = 2; i * i <= x; ++i)
    if (x % i == 0) return false;
  return true;
}
inline long long qpow(long long a, long long n) {
  long long t = 1;
  while (n) {
    if (n & 1) t = t * a % mod;
    a = a * a % mod, n >>= 1;
  }
  return t % mod;
}
int a[maxn];
int pos[maxn];
vector<int> p[maxn];
bool vis[maxn];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  long long ans = 0;
  for (int i = 1; i <= m; i++) {
    scanf("%d", &a[i]);
    p[a[i]].push_back(i);
  }
  for (int i = 1; i < m; i++) ans += abs(a[i] - a[i + 1]);
  printf("%lld ", ans);
  for (int i = 2; i <= n; i++) {
    for (auto v : p[i]) {
      if (v - 1 >= 1) ans -= abs(i - a[v - 1]);
      if (v + 1 <= m) ans -= abs(i - a[v + 1]);
      vis[v] = 1;
    }
    for (auto v : p[i - 1]) {
      if (v - 1 >= 1 && !vis[v - 1]) ans -= abs(a[v] - a[v - 1]);
      if (v + 1 <= m && !vis[v + 1]) ans -= abs(a[v] - a[v + 1]);
    }
    for (auto v : p[i - 1]) a[v] = i;
    for (auto v : p[i]) a[v] = 1, vis[v] = 0;
    for (auto v : p[i]) {
      if (v - 1 >= 1) ans += abs(a[v] - a[v - 1]);
      if (v + 1 <= m) ans += abs(a[v] - a[v + 1]);
      vis[v] = 1;
    }
    for (auto v : p[i - 1]) {
      if (v - 1 >= 1 && !vis[v - 1]) ans += abs(a[v] - a[v - 1]);
      if (v + 1 <= m && !vis[v + 1]) ans += abs(a[v] - a[v + 1]);
    }
    for (auto v : p[i - 1]) a[v] = i, vis[v] = 0;
    for (auto v : p[i]) a[v] = 1, vis[v] = 0;
    printf("%lld ", ans);
  }
  return 0;
}
