#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << "=" << a << " ! ";
  err(++it, args...);
}
const long long N = 5e5 + 7, M = 1e9 + 7;
long long a[N], p[N];
vector<long long> g[N];
long long n, m, i, x, t;
void chn(long long x, long long i, long long j) {
  p[x] = j;
  for (long long y : g[x]) t += abs(j - p[y]) - abs(i - p[y]);
}
int main() {
  cin >> n >> m;
  for (i = 1; i <= n; i++) p[i] = i;
  for (i = 1; i <= m; i++) {
    cin >> x;
    a[i] = x;
    if (i > 1 and x != a[i - 1]) {
      g[x].push_back(a[i - 1]);
      g[a[i - 1]].push_back(x);
      t += abs(x - a[i - 1]);
    }
  }
  cout << t << " ";
  for (i = 2; i <= n; i++) {
    chn(i - 1, 1, i);
    chn(i, i, 1);
    cout << t << " \n"[i == n];
  }
}
