#include <bits/stdc++.h>
using namespace std;
long long total;
long long cont[200100];
long long V[200100];
int N;
long long st[800100];
long long lazy[800100];
void push(int node, int lo, int hi) {
  if (lazy[node] == 0) return;
  st[node] += lazy[node];
  if (lo != hi) {
    lazy[2 * node + 1] += lazy[node];
    lazy[2 * node + 2] += lazy[node];
  }
  lazy[node] = 0;
}
void update(int s, int e, long long x, int lo = 0, int hi = -1, int node = 0) {
  if (hi == -1) hi = N - 1;
  push(node, lo, hi);
  if (hi < s || lo > e) return;
  if (lo >= s && hi <= e) {
    lazy[node] = x;
    push(node, lo, hi);
    return;
  }
  int mid = (lo + hi) / 2;
  update(s, e, x, lo, mid, 2 * node + 1);
  update(s, e, x, mid + 1, hi, 2 * node + 2);
  st[node] = max(st[2 * node + 1], st[2 * node + 2]);
}
long long query(int s, int e, int lo = 0, int hi = -1, int node = 0) {
  if (hi == -1) hi = N - 1;
  push(node, lo, hi);
  if (hi < s || lo > e) return -0x3f3f3f3f;
  if (lo >= s && hi <= e) return st[node];
  int mid = (lo + hi) / 2;
  return max(query(s, e, lo, mid, 2 * node + 1),
             query(s, e, mid + 1, hi, 2 * node + 2));
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  N = n;
  for (int i = 0; i < m; i++) scanf("%lld", &V[i]);
  for (int i = 1; i < m; i++) total += abs(V[i] - V[i - 1]);
  for (int i = 1; i < m; i++) {
    if (V[i - 1] == V[i]) continue;
    if (V[i - 1] > V[i]) {
      cont[V[i]] += V[i - 1] - 1 - abs(V[i] - V[i - 1]);
      cont[V[i - 1]] += V[i] - abs(V[i] - V[i - 1]);
    } else {
      cont[V[i]] += V[i - 1] - abs(V[i] - V[i - 1]);
      cont[V[i - 1]] += V[i] - 1 - abs(V[i] - V[i - 1]);
    }
  }
  for (int i = 1; i < m; i++) {
    if (V[i - 1] == V[i]) continue;
    int a = min(V[i - 1], V[i]);
    int b = max(V[i - 1], V[i]) - 2;
    update(a, b, -1);
  }
  for (int i = 1; i <= n; i++) {
    long long x = query(i - 1, i - 1);
    printf("%lld ", total + cont[i] + x);
  }
  printf("\n");
  return 0;
}
