#include <bits/stdc++.h>
using namespace std;
int n, m, a[200005], wei[200005];
long long ans;
vector<int> t[200005];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) wei[i] = i;
  for (int i = 1; i < m; i++) {
    t[a[i]].push_back(a[i + 1]);
    t[a[i + 1]].push_back(a[i]);
    ans += abs(a[i] - a[i + 1]);
  }
  cout << ans << ' ';
  for (int i = 2; i <= n; i++) {
    int now = i;
    for (int j = 0; j < t[now].size(); j++) {
      if (t[now][j] == i - 1 || t[now][j] == i) continue;
      if (wei[t[now][j]] > wei[now]) {
        ans += wei[now] - 1;
      } else {
        ans += wei[t[now][j]] - 1 - (wei[now] - wei[t[now][j]]);
      }
    }
    now = i - 1;
    for (int j = 0; j < t[now].size(); j++) {
      if (t[now][j] == i || t[now][j] == i - 1) continue;
      if (wei[t[now][j]] > wei[i])
        ans -= wei[i] - 1;
      else
        ans += wei[i] - 2 * wei[t[now][j]] + 1;
    }
    wei[i - 1] = wei[i];
    wei[i] = 1;
    cout << ans << ' ';
  }
}
