#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 1e9 + 7;
long long power(long long a, long long b, long long m = mod) {
  long long x = 1;
  while (b) {
    if (b & 1) {
      x = 1ll * x * a % m;
    }
    a = 1ll * a * a % m;
    b /= 2;
  }
  return x;
}
const int N = 2e6 + 9;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<long long> a(m + 1), sum_to_small(n + 1), to_big(n + 1),
      to_small(n + 1);
  for (int i = 1; i <= m; i++) {
    cin >> a[i];
  }
  long long ans = 0;
  for (int i = 1; i < m; i++) {
    int u = a[i], v = a[i + 1];
    if (u == v) continue;
    if (u < v) swap(u, v);
    ans += u - v;
    to_big[v]++;
    to_small[u]++;
    sum_to_small[u] += v;
  }
  long long cur = 0;
  for (int i = 1; i <= n; i++) {
    cur -= to_small[i];
    long long tmp =
        ans - cur + 2 * sum_to_small[i] - to_small[i] * i + to_big[i] * (i - 1);
    cout << tmp << " ";
    cur += to_big[i];
  }
  return 0;
}
