#include <bits/stdc++.h>
using namespace std;
int n, m, id;
vector<int> v, pos;
vector<vector<int>> fir, sec;
vector<long long> ans;
void solve(int val, vector<vector<int>> &vt, int val2, int org) {
  for (int i = 0; i < vt[val].size(); i++)
    if (vt[val][i] != val && vt[val][i] != val2)
      ans[id] += -abs(org - pos[vt[val][i]]) + abs(pos[val] - pos[vt[val][i]]);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  fir.resize(n + 1);
  sec.resize(n + 1);
  pos.resize(n + 1);
  for (int i = 1; i <= n; i++) pos[i] = i;
  v.resize(m);
  for (int i = 0; i < m; i++) cin >> v[i];
  for (int i = 0; i < m - 1; i++)
    fir[v[i]].push_back(v[i + 1]), sec[v[i + 1]].push_back(v[i]);
  ans.resize(n + 1);
  for (int i = 0; i < m - 1; i++) ans[1] += abs(v[i] - v[i + 1]);
  for (int i = 2; i <= n; i++) {
    id = i;
    ans[i] = ans[i - 1];
    swap(pos[i - 1], pos[i]);
    solve(i, fir, i - 1, pos[i - 1]);
    solve(i - 1, fir, i, pos[i]);
    solve(i, sec, i - 1, pos[i - 1]);
    solve(i - 1, sec, i, pos[i]);
  }
  for (int i = 1; i <= n; i++) cout << ans[i] << " ";
  return 0;
}
