package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var reader io.Reader
var scanner *bufio.Scanner

func Init(io io.Reader, max_token_size int) {
	reader = bufio.NewReader(io)
	scanner = bufio.NewScanner(reader)
	// max token size
	scanner.Split(bufio.ScanWords)
	scanner.Buffer([]byte{}, max_token_size)
}

func stderr(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func NextInt() int {
	bytes := NextBytes()
	i, err := Atoi(bytes)
	if err != nil {
		die(err)
	}
	return i
}
func NextInt64() int64 {
	bytes := NextBytes()
	i, err := Atoi64(bytes)
	if err != nil {
		die(err)
	}
	return i
}

func NextBytes() []byte {
	if !scanner.Scan() {
		die(scanner.Err())
	}
	bytes := scanner.Bytes()
	copied := make([]byte, len(bytes))
	copy(copied, bytes)
	return copied
}

func Atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func Atoi64(b []byte) (int64, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int64(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func ExtendByteArray(a []byte, size int) []byte {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]byte, size-len(a))...)
	}
}

func ExtendIntArray(a []int, size int) []int {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]int, size-len(a))...)
	}
}

func reverseInts(a []int) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

func unique(a []int) int {
	newLen := 0
	n := len(a)
	for i := 0; i < n; i++ {
		if newLen == 0 || a[i] != a[newLen-1] {
			a[newLen] = a[i]
			newLen++
		}
	}
	return newLen
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 1000010)

	n, m := NextInt(), NextInt()
	l := make([]int, m)
	p := make([]int, m)
	for i := 0; i < m; i++ {
		l[i] = NextInt()
		if i+l[i] > n {
			fmt.Fprintln(out, -1)
			return
		}
	}
	mr := make([]int, m)
	for i := m - 1; i >= 0; i-- {
		if i == m-1 {
			mr[i] = i + l[i]
		} else {
			mr[i] = max(mr[i+1], i+l[i])
		}
	}

	var r int
	for i, lp := 0, 0; i < m; i++ {
		maxAdd := n - mr[i] - (lp - i)
		if maxAdd < 0 {
			panic("maxAdd < 0")
		}
		k := min(maxAdd, r-lp)
		p[i] = lp + k
		lp += k
		r = max(p[i]+l[i], r)
	}

	if r != n {
		fmt.Fprintln(out, -1)
		return
	}

	for i := 0; i < m; i++ {
		fmt.Fprint(out, p[i]+1, " ")
	}
	fmt.Fprintln(out)
}

package main
import (
	"fmt"
)

func main() {
	var n, m, aux, sum, i, v int64
	var l, ans []int64
	fmt.Scan(&n, &m)

	for i = 0; i < m; i++ {
		fmt.Scan(&aux)
		l = append(l, aux)
		sum += aux
	}

	if dif := sum - n; dif < 0 {
		fmt.Println("-1")
	} else {
		p := int64(1)
		for _, v = range l {
			if p > n - v + 1 {
				fmt.Println("-1")
				return
			}
			ans = append(ans, p)
			if v-1 >= dif {
				p += v - dif
				dif = 0
			} else {
				p++
				dif -= v-1
			}
		}

		for _, v := range ans {
			fmt.Print(v, " ")
		}
		fmt.Println()
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func CF1329A(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}

	var n, m int
	Fscan(in, &n, &m)
	l := make([]int, m)
	r := make([]int, m)
	p := make([]int, m)
	for i := range l {
		Fscan(in, &l[i])
		if i == 0 {
			r[i] = l[i]
		} else {
			r[i] = max(r[i-1], l[i]+i)
		}
		if r[i] > n {
			Fprint(out, -1)
			return
		}
		p[i] = i + 1
	}
	last := n
	i := m - 1
	for ; i >= 0 && r[i] < last; i-- {
		p[i] = last - l[i] + 1
		last = p[i] - 1
	}
	if i < 0 && last > 0 {
		Fprint(out, -1)
		return
	}
	for _, v := range p {
		Fprint(out, v, " ")
	}
}

func main() { CF1329A(os.Stdin, os.Stdout) }

package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func flush()                            { writer.Flush() }
func pp(a interface{})                  { fmt.Println(a) }

var arr []int
var n, p int

func main() {
	defer flush()

	scanf("%d %d\n", &n, &p)
	arr = make([]int, p)
	for i := range arr {
		scanf("%d", &arr[i])
	}
	solve()
}

func solve() {
	curi := 0
	lmin, lmax := 1, 1
	var sum int64 = 0
	res := []int{}
	for _, x := range arr {
		sum += int64(x)
	}
	for true {
		if curi >= p {
			printf("-1")
			return
		}
		rest := n - lmax + 1
		if curi == p-1 && (n-lmin+1) < arr[curi] {
			printf("-1")
			return
		}
		if sum < int64(rest) {
			printf("-1")
			return
		}
		if sum-int64(arr[curi]) <= int64(rest) {
			pad := rest - int((sum - int64(arr[curi])))
			target := lmax + pad - arr[curi]
			// fmt.Println(target, lmin, lmax)
			if target >= lmin {
				res = append(res, target)
				pos := lmax + pad
				curi++
				for curi < p {
					res = append(res, pos)
					pos += arr[curi]
					curi++
				}
				for i := range res {
					if i != 0 {
						printf(" ")
					}
					printf("%d", res[i])
				}
				return
			}
		}
		res = append(res, lmin)
		lmin, lmax = lmin+1, max(lmax, lmin+arr[curi])
		sum -= int64(arr[curi])
		curi++
	}
}

// utilities function
func pow(a, b int) int {
	p := 1
	for b > 0 {
		if b&1 != 0 {
			p *= a
		}
		a, b = a*a, b>>1
	}
	return p
}

func powmod(a, b, m int) int {
	a = a % m
	p := 1 % m
	for b > 0 {
		if b&1 != 0 {
			p = (p * a) % m
		}
		a, b = (a*a)%m, b>>1
	}
	return p
}

func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func chmax(a *int, b int) {
	*a = max(*a, b)
}

func chmin(a *int, b int) {
	*a = min(*a, b)
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
	"sync"
)

const SIZE int64 = 100002

var(
	lenner [SIZE]int64
	suffix_sum [SIZE]int64
)

func solve() {
	N, M := scanInt64(), scanInt64()
	for i := int64(1) ; i <= M; i++ {
		lenner[i] = scanInt64()
		if lenner[i] + i - 1 > N {
			err()
			return
		}
	}
	for i := M; i > 0; i-- {
		suffix_sum[i] = suffix_sum[i + 1] + lenner[i]
	}
	if suffix_sum[1] < N {
		err()
		return
	}
	for i := int64(1); i <= M; i++ {
		_, _ = printFmt(max(i, N - suffix_sum[i] + 1))
		if i < M {
			_, _ = printFmt(" ")
		} else {
			_, _ = printFmt("")
		}
	}
}

func err() {
	_, _ = printFmt("-1")
}

func main() {
	solve()
}
/*********************** I/O ***********************/

var channelType chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var printFmt func(a ...interface{}) (n int, err error)

func init() {
	printFmt = fmt.Print

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	channelType = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range channelType {
			_, _ = writer.WriteString(line + "\n")
		}
	}()
}

func scanString() string {in.Scan(); return in.Text() }
func scanInt() int {i, _ := strconv.Atoi(scanString()); return i}
func scanInt64() int64 {i, _ := strconv.ParseInt(scanString(), 10, 64); return i}
func scanStringSlice(n int) []string {s := make([]string, n); for i := 0; i < n; i++ {s[i] = scanString()}; return s}
func scanIntSlice(n int) []int {arr := make([]int, n); for i := 0; i < n; i++ {arr[i] = scanInt()}; return arr}
func scanInt64Slice(n int) []int64 {arr := make([]int64, n); for i := 0; i < n; i++ {arr[i] = scanInt64()}; return arr}

/*********************** Utils ***********************/

func stringEquivalent(v interface{}) string {return fmt.Sprintf("%v", v)}
func spaceSeperatedStringFromArray(a []int) string {sb := strings.Builder{}; sb.Grow(len(a) * 9); for i := range a {sb.WriteString(strconv.Itoa(a[i]) + " ")}; return sb.String()}
func spaceSeperatedStringFromArray64(a []int64) string {sb := strings.Builder{}; sb.Grow(len(a) * 9); for i := range a {sb.WriteString(strconv.FormatInt(a[i], 10) + " ")}; return sb.String()}
func minMaxFromArray(args ...int64) (int64, int64) {minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64); for _, v := range args {if v < minVal {minVal = v}; if v > maxVal {maxVal = v}}; return minVal, maxVal}
func minElementFromArray(args ...int64) int64 { mn, _ := minMaxFromArray(args...); return mn }
func maxElementFromArray(args ...int64) int64 { _, mx := minMaxFromArray(args...); return mx }
func lcmCalculation(a, b int64) int64 {return a / gcdCalculation(a, b) * b}
func gcdCalculation(a, b int64) int64 {if a == 0 {return b}; return gcdCalculation(b%a, a)}
func sortInt64Slice(a []int64) {sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })}
func absoluteValue(x int64) int64 {if x < 0 {return -x}; return x}
func min(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func max(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}

/*
URL:
https://codeforces.com/problemset/problem/1329/A
*/

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	n, m int
	L    []int64
)

func main() {
	n, m = ReadInt2()
	L = ReadInt64Slice(m)

	total := Sum(L...)

	if total < int64(n) {
		fmt.Println(-1)
		return
	}

	for i := 0; i < m; i++ {
		if L[i] > int64(n-i) {
			fmt.Println(-1)
			return
		}
	}

	diff := total - int64(n)
	for i := 0; i < m; i++ {
		l := L[i]
		if diff >= l-1 {
			L[i] = 1
			diff -= l - 1
		} else {
			L[i] -= diff
			diff = 0
		}

		if diff <= 0 {
			break
		}
	}

	A := make([]int64, m)
	idx := int64(1)
	cs := int64(0)
	for i := 0; i < m; i++ {
		A[i] = idx + cs
		cs += L[i]
	}

	fmt.Println(PrintInts64Line(A...))
}

// Sum returns multiple integers sum.
func Sum(integers ...int64) int64 {
	var s int64

	s = 0
	for _, i := range integers {
		s += i
	}

	return s
}

/*******************************************************************/

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func flush()                            { writer.Flush() }
func pp(a interface{})                  { fmt.Println(a) }

var arr []int
var n, p int

func main() {
	defer flush()

	scanf("%d %d\n", &n, &p)
	arr = make([]int, p)
	for i := range arr {
		scanf("%d", &arr[i])
	}
	solve()
}

func solve() {
	curi := 0
	lmin, lmax := 1, 1
	sum := 0
	res := []int{}
	for _, x := range arr {
		sum += x
	}
	for true {
		if curi >= p {
			printf("-1")
			return
		}
		rest := n - lmax + 1
		if curi == p-1 && (n-lmin+1) < arr[curi] {
			printf("-1")
			return
		}
		if sum < rest {
			printf("-1")
			return
		}
		if sum-arr[curi] <= rest {
			pad := rest - (sum - arr[curi])
			target := lmax + pad - arr[curi]
			// fmt.Println(target, lmin, lmax)
			if target >= lmin {
				res = append(res, target)
				pos := lmax + pad
				curi++
				for curi < p {
					res = append(res, pos)
					pos += arr[curi]
					curi++
				}
				for i := range res {
					if i != 0 {
						printf(" ")
					}
					printf("%d", res[i])
				}
				return
			}
		}
		res = append(res, lmin)
		lmin, lmax = lmin+1, max(lmax, lmin+arr[curi])
		sum -= arr[curi]
		curi++
	}
}

// utilities function
func pow(a, b int) int {
	p := 1
	for b > 0 {
		if b&1 != 0 {
			p *= a
		}
		a, b = a*a, b>>1
	}
	return p
}

func powmod(a, b, m int) int {
	a = a % m
	p := 1 % m
	for b > 0 {
		if b&1 != 0 {
			p = (p * a) % m
		}
		a, b = (a*a)%m, b>>1
	}
	return p
}

func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func chmax(a *int, b int) {
	*a = max(*a, b)
}

func chmin(a *int, b int) {
	*a = min(*a, b)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func flush()                            { writer.Flush() }
func pp(a interface{})                  { fmt.Println(a) }

var arr []int
var n, p int

func main() {
	defer flush()

	scanf("%d %d\n", &n, &p)
	arr = make([]int, p)
	for i := range arr {
		scanf("%d", &arr[i])
	}
	solve()
}

func printRes(i, pos int, res []int) {
	for i < p {
		res = append(res, pos)
		pos += arr[i]
		i++
	}
	for i := range res {
		if i != 0 {
			printf(" ")
		}
		printf("%d", res[i])
	}
}

func solve() {
	curi := 0
	lmin, lmax := 1, 1
	sum := 0
	res := []int{}
	for _, x := range arr {
		sum += x
	}
	for true {
		if curi >= p {
			printf("-1")
			return
		}
		rest := n - lmax + 1
		if curi == p-1 && (n-lmin+1) < arr[curi] {
			printf("-1")
			return
		}
		if sum < rest {
			printf("-1")
			return
		}
		if sum-arr[curi] <= rest {
			pad := rest - (sum - arr[curi])
			target := lmax + pad - arr[curi]
			// fmt.Println(target, lmin, lmax)
			if target >= lmin {
				res = append(res, target)
				printRes(curi+1, lmax+pad, res)
				return
			}
		}
		res = append(res, lmin)
		lmin, lmax = lmin+1, max(lmax, lmin+arr[curi])
		sum -= arr[curi]
		curi++
	}
}

// utilities function
func pow(a, b int) int {
	p := 1
	for b > 0 {
		if b&1 != 0 {
			p *= a
		}
		a, b = a*a, b>>1
	}
	return p
}

func powmod(a, b, m int) int {
	a = a % m
	p := 1 % m
	for b > 0 {
		if b&1 != 0 {
			p = (p * a) % m
		}
		a, b = (a*a)%m, b>>1
	}
	return p
}

func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func chmax(a *int, b int) {
	*a = max(*a, b)
}

func chmin(a *int, b int) {
	*a = min(*a, b)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func flush()                            { writer.Flush() }
func pp(a interface{})                  { fmt.Println(a) }

var arr []int
var n, p int

func main() {
	defer flush()

	scanf("%d %d\n", &n, &p)
	arr = make([]int, p)
	for i := range arr {
		scanf("%d", &arr[i])
	}
	solve()
}

func printRes(i, pos int, res []int) {
	for i < p {
		res = append(res, pos)
		pos += arr[i]
		i++
	}
	for i := range res {
		if i != 0 {
			printf(" ")
		}
		printf("%d", res[i])
	}
}

func solve() {
	curi := 0
	lmin, lmax := 1, 1
	sum := 0
	res := []int{}
	for _, x := range arr {
		sum += x
	}
	for true {
		if curi >= p {
			printf("-1")
			return
		}
		rest := n - lmax + 1
		if sum < rest {
			printf("-1")
			return
		}
		if sum == rest {
			printRes(curi, lmax, res)
			return
		}
		if sum-arr[curi] <= rest {
			pad := rest - (sum - arr[curi])
			target := lmax + pad - arr[curi]
			// fmt.Println(target, lmin, lmax)
			if target >= lmin {
				res = append(res, target)
				printRes(curi+1, lmax+pad, res)
				return
			}
		}
		res = append(res, lmin)
		lmin, lmax = lmin+1, max(lmax, lmin+arr[curi])
		sum -= arr[curi]
		curi++
	}
}

// utilities function
func pow(a, b int) int {
	p := 1
	for b > 0 {
		if b&1 != 0 {
			p *= a
		}
		a, b = a*a, b>>1
	}
	return p
}

func powmod(a, b, m int) int {
	a = a % m
	p := 1 % m
	for b > 0 {
		if b&1 != 0 {
			p = (p * a) % m
		}
		a, b = (a*a)%m, b>>1
	}
	return p
}

func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func flush()                            { writer.Flush() }
func pp(a interface{})                  { fmt.Println(a) }

var arr []int
var n, p int

func main() {
	defer flush()

	scanf("%d %d\n", &n, &p)
	arr = make([]int, p)
	for i := range arr {
		scanf("%d", &arr[i])
	}
	solve()
}

func printRes(i, pos int, res []int) {
	for i < p {
		res = append(res, pos)
		pos += arr[i]
		i++
	}
	for i := range res {
		if i != 0 {
			printf(" ")
		}
		printf("%d", res[i])
	}
}

func solve() {
	curi := 0
	lmin, lmax := 1, 1
	sum := 0
	res := []int{}
	for _, x := range arr {
		sum += x
	}
	for true {
		if curi >= p {
			printf("-1")
			break
		}
		rest := n - lmax + 1
		// fmt.Println(res, lmin, lmax, rest, sum)
		if sum < rest {
			printf("-1")
			break
		}
		if sum == rest {
			printRes(curi, lmax, res)
			break
		}
		if sum-arr[curi] <= rest {
			pad := rest - (sum - arr[curi])
			target := lmax + pad - arr[curi]
			if target >= lmin {
				res = append(res, target)
				printRes(curi+1, lmax+pad, res)
				break
			}
		}
		res = append(res, lmin)
		lmin, lmax = lmin+1, max(lmax, lmin+arr[curi])
		sum -= arr[curi]
		curi++
	}
}

// utilities function
func pow(a, b int) int {
	p := 1
	for b > 0 {
		if b&1 != 0 {
			p *= a
		}
		a, b = a*a, b>>1
	}
	return p
}

func powmod(a, b, m int) int {
	a = a % m
	p := 1 % m
	for b > 0 {
		if b&1 != 0 {
			p = (p * a) % m
		}
		a, b = (a*a)%m, b>>1
	}
	return p
}

func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func chmax(a *int, b int) {
	*a = max(*a, b)
}

func chmin(a *int, b int) {
	*a = min(*a, b)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func flush()                            { writer.Flush() }
func pp(a interface{})                  { fmt.Println(a) }

var arr []int
var n, p int

func main() {
	defer flush()

	scanf("%d %d\n", &n, &p)
	arr = make([]int, p)
	for i := range arr {
		scanf("%d", &arr[i])
	}
	solve()
}

func printRes(i, pos int, res []int) {
	for i < p {
		res = append(res, pos)
		pos += arr[i]
		i++
	}
	for i := range res {
		if i != 0 {
			printf(" ")
		}
		printf("%d", res[i])
	}
}

func solve() {
	curi := 0
	lmin, lmax := 1, 1
	sum := 0
	res := []int{}
	for _, x := range arr {
		sum += x
	}
	for true {
		if curi >= p {
			printf("-1")
			break
		}
		rest := n - lmax + 1
		// fmt.Println(res, lmin, lmax, rest, sum)
		if sum < rest {
			printf("-1")
			break
		}
		if sum == rest {
			printRes(curi, lmax, res)
			break
		}
		if sum-arr[curi] <= rest {
			pad := rest - (sum - arr[curi])
			target := lmax + pad - arr[curi]
			if target >= lmin {
				res = append(res, target)
				printRes(curi+1, lmax+pad, res)
				break
			}
		}
		res = append(res, lmin)
		lmin, lmax = lmin+1, max(lmax, lmin+arr[curi]+1)
		sum -= arr[curi]
		curi++
	}
}

// utilities function
func pow(a, b int) int {
	p := 1
	for b > 0 {
		if b&1 != 0 {
			p *= a
		}
		a, b = a*a, b>>1
	}
	return p
}

func powmod(a, b, m int) int {
	a = a % m
	p := 1 % m
	for b > 0 {
		if b&1 != 0 {
			p = (p * a) % m
		}
		a, b = (a*a)%m, b>>1
	}
	return p
}

func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func chmax(a *int, b int) {
	*a = max(*a, b)
}

func chmin(a *int, b int) {
	*a = min(*a, b)
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
	"sync"
)

const SIZE = 100002

var(
	lenner [SIZE]int
	suffix_sum [SIZE]int
)

func solve() {
	N, M := scanInt(), scanInt()
	for i := 1; i <= M; i++ {
		lenner[i] = scanInt()
		if lenner[i] + i - 1 > N {
			err()
			return
		}
	}
	for i := M; i > 0; i-- {
		suffix_sum[i] = suffix_sum[i + 1] + lenner[i]
	}
	if suffix_sum[1] < N {
		err()
		return
	}
	for i := 1; i <= M; i++ {
		_, _ = printFmt(max(i, N - suffix_sum[i] + 1))
		if i < M {
			_, _ = printFmt(" ")
		} else {
			_, _ = printFmt("")
		}
	}
}

func err() {
	_, _ = printFmt("-1")
}

func main() {
	solve()
}
/*********************** I/O ***********************/

var channelType chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var printFmt func(a ...interface{}) (n int, err error)

func init() {
	printFmt = fmt.Print

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	channelType = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range channelType {
			_, _ = writer.WriteString(line + "\n")
		}
	}()
}

func scanString() string {in.Scan(); return in.Text() }
func scanInt() int {i, _ := strconv.Atoi(scanString()); return i}
func scanInt64() int64 {i, _ := strconv.ParseInt(scanString(), 10, 64); return i}
func scanStringSlice(n int) []string {s := make([]string, n); for i := 0; i < n; i++ {s[i] = scanString()}; return s}
func scanIntSlice(n int) []int {arr := make([]int, n); for i := 0; i < n; i++ {arr[i] = scanInt()}; return arr}
func scanInt64Slice(n int) []int64 {arr := make([]int64, n); for i := 0; i < n; i++ {arr[i] = scanInt64()}; return arr}

/*********************** Utils ***********************/

func stringEquivalent(v interface{}) string {return fmt.Sprintf("%v", v)}
func spaceSeperatedStringFromArray(a []int) string {sb := strings.Builder{}; sb.Grow(len(a) * 9); for i := range a {sb.WriteString(strconv.Itoa(a[i]) + " ")}; return sb.String()}
func spaceSeperatedStringFromArray64(a []int64) string {sb := strings.Builder{}; sb.Grow(len(a) * 9); for i := range a {sb.WriteString(strconv.FormatInt(a[i], 10) + " ")}; return sb.String()}
func minMaxFromArray(args ...int64) (int64, int64) {minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64); for _, v := range args {if v < minVal {minVal = v}; if v > maxVal {maxVal = v}}; return minVal, maxVal}
func minElementFromArray(args ...int64) int64 { mn, _ := minMaxFromArray(args...); return mn }
func maxElementFromArray(args ...int64) int64 { _, mx := minMaxFromArray(args...); return mx }
func lcmCalculation(a, b int64) int64 {return a / gcdCalculation(a, b) * b}
func gcdCalculation(a, b int64) int64 {if a == 0 {return b}; return gcdCalculation(b%a, a)}
func sortInt64Slice(a []int64) {sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })}
func absoluteValue(x int64) int64 {if x < 0 {return -x}; return x}
func min(args ...int) int { mn, _ := MnMx(args...); return mn }
func max(args ...int) int { _, mx := MnMx(args...); return mx }
func MnMx(args ...int) (int, int) {
	minVal, maxVal := math.MaxInt32, math.MinInt32
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}

package main
import (
	"fmt"
)

func main() {
	var n, m, aux, sum int
	var l, ans []int
	fmt.Scan(&n, &m)

	for i := 0; i < m; i++ {
		fmt.Scan(&aux)
		l = append(l, aux)
		sum += aux
	}

	if dif := sum - n; dif < 0 {
		fmt.Println("-1")
	} else {
		p := 1
		for _, v := range l {
			if p > n - v + 1 {
				fmt.Println("-1")
				return
			}
			ans = append(ans, p)
			if v-1 > dif {
				p += v - dif
				dif = 0
			} else {
				p++
				dif -= v-1
			}
		}

		for _, v := range ans {
			fmt.Print(v, " ")
		}
		fmt.Println()
	}
}

package main
import (
	"fmt"
)

func main() {
	var n, m, aux, sum int
	var l, ans []int
	fmt.Scan(&n, &m)

	for i := 0; i < m; i++ {
		fmt.Scan(&aux)
		l = append(l, aux)
		sum += aux
	}

	if dif := sum - n; dif < 0 {
		fmt.Println("-1")
	} else {
		p := 1
		for _, v := range l {
			if p > n - v + 1 {
				fmt.Println("-1")
				return
			}
			ans = append(ans, p)
			if v-1 >= dif {
				p += v - dif
				dif = 0
			} else {
				p++
				dif -= v-1
			}
		}

		for _, v := range ans {
			fmt.Print(v, " ")
		}
		fmt.Println()
	}
}

package main
import "fmt"

func min(a, b int) int {
	if a < b { return a }
	return b
}

func main() {
	var n, m, aux int
	var anss []int
	ans := 1
	fmt.Scan(&n, &m)

	for i := 1; i <= m; i++ {
		fmt.Scan(&aux)
		anss = append(anss, ans)
		if i != m-1 && min(n - (m-i), aux + ans - 1) <= ans {
			fmt.Println("-1")
			return
		}
		ans = min(n - (m-i), aux + ans - 1)
	}
	if aux + anss[len(anss)-1] - 1 != n {
		fmt.Println("-1")
	} else {
		for _, v := range anss {
			fmt.Print(v, " ")
		}
		fmt.Println()
	}
}

package main
import "fmt"

func min(a, b int) int {
	if a < b { return a }
	return b
}

func main() {
	var n, m, aux int
	var anss []int
	ans := 1
	fmt.Scan(&n, &m)

	for i := 1; i <= m; i++ {
		fmt.Scan(&aux)
		anss = append(anss, ans)
		if i != m && min(n - (m-i), aux + ans - 1) <= ans {
			fmt.Println("-1")
			return
		}
		ans = min(n - (m-i), aux + ans - 1)
	}
	if aux + anss[len(anss)-1] - 1 != n {
		fmt.Println("-1")
	} else {
		for _, v := range anss {
			fmt.Print(v, " ")
		}
		fmt.Println()
	}
}

package main
import "fmt"

func min(a, b int) int {
	if a < b { return a }
	return b
}

func main() {
	var n, m, aux int
	var anss []int
	ans := 1
	fmt.Scan(&n, &m)

	for i := 1; i <= m; i++ {
		fmt.Scan(&aux)
		anss = append(anss, ans)
		if temp := min(n - (m-i), aux + ans - 1); temp <= ans {
			fmt.Println("-1")
			return
		}
		ans = min(n - (m-i), aux + ans - 1)
	}
	if aux + anss[len(anss)-1] - 1 != n {
		fmt.Println("-1")
	} else {
		for _, v := range anss {
			fmt.Print(v, " ")
		}
		fmt.Println()
	}
}

package main
import "fmt"

func min(a, b int) int {
	if a < b { return a }
	return b
}

func main() {
	var n, m, aux int
	var anss []int
	ans := 1
	fmt.Scan(&n, &m)

	for i := 1; i <= m; i++ {
		fmt.Scan(&aux)
		anss = append(anss, ans)
		ans = min(n - (m-i), aux + ans - 1)
	}
	if aux + anss[len(anss)-1] - 1 != n {
		fmt.Println("-1")
	} else {
		for _, v := range anss {
			fmt.Print(v, " ")
		}
		fmt.Println()
	}
}


package main

import (
	"bufio"
	"fmt"
	"os"
	//"strconv"
)

func subAbs(x, y int) int64 {
	if x >= y {
		return int64(x - y)
	} else {
		return int64(y - x)
	}
}

type Node struct {
	old       int
	pre, next bool
}

func main() {
	reader := bufio.NewReader(os.Stdin)

	var n, m int
	fmt.Fscanf(reader, "%d %d\n", &n, &m)

	mapp := make(map[int][]int, m)

	x := make([]Node, m+2)

	for i := 1; i <= m; i++ {
		fmt.Fscanf(reader, "%d", &x[i].old)

		if slice, ok := mapp[x[i].old]; ok {
			mapp[x[i].old] = append(slice, i)
		} else {
			slice := make([]int, 1, 10)
			slice[0] = i
			mapp[x[i].old] = slice
		}
	}

	var sum int64 = 0
	for i := 2; i <= m; i++ {
		sum += subAbs(x[i].old, x[i-1].old)
	}
	//var ans string = strconv.Itoa(sum)
	fmt.Printf("%d ", sum)

	for i := 2; i <= n; i++ {

		x[1].pre = true
		x[m].next = true
		pi_, _ := mapp[i-1]
		pi, _ := mapp[i]

		for _, index := range pi_ {
			if !x[index].pre && !x[index-1].next {
				sum -= subAbs(x[index].old, x[index-1].old)
				x[index].pre = true
			}

			if !x[index].next && !x[index+1].pre {
				sum -= subAbs(x[index].old, x[index+1].old)
				x[index].next = true
			}
		}

		for _, index := range pi {
			if !x[index].pre && !x[index-1].next {
				sum -= subAbs(x[index].old, x[index-1].old)
				x[index].pre = true
			}

			if !x[index].next && !x[index+1].pre {
				sum -= subAbs(x[index].old, x[index+1].old)
				x[index].next = true
			}
		}

		for _, index := range pi_ {
			x[index].pre = false
			x[index].next = false
			x[index].old = i
		}

		for _, index := range pi {
			x[index].pre = false
			x[index].next = false
			x[index].old = 1
		}

		// for k := 1; k <= m; k++ {
		// 	fmt.Printf("%d ", x[k].old)
		// }
		// fmt.Println()

		x[1].pre = true
		x[m].next = true
		for _, index := range pi_ {
			if !x[index].pre && !x[index-1].next {
				sum += subAbs(x[index].old, x[index-1].old)
				x[index].pre = true
			}

			if !x[index].next && !x[index+1].pre {
				sum += subAbs(x[index].old, x[index+1].old)
				x[index].next = true
			}
		}

		for _, index := range pi {
			if !x[index].pre && !x[index-1].next {
				sum += subAbs(x[index].old, x[index-1].old)
				x[index].pre = true
			}

			if !x[index].next && !x[index+1].pre {
				sum += subAbs(x[index].old, x[index+1].old)
				x[index].next = true
			}
		}

		for _, index := range pi_ {
			x[index].pre = false
			x[index].next = false
		}

		for _, index := range pi {
			x[index].pre = false
			x[index].next = false
		}

		fmt.Printf("%d ", sum)
	}

	//fmt.Println(ans)
	fmt.Println()
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	reader *bufio.Reader = bufio.NewReader(os.Stdin)
	writer *bufio.Writer = bufio.NewWriter(os.Stdout)
	Debug                = true
)

func Printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func Scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func Dprint(format string, a ...interface{}) {
	if Debug {
		fmt.Fprintf(os.Stderr, format+"\n", a...)
	}
}

func autoswp(x, y int) (int, int) {
	if y < x {
		return y, x
	}
	return x, y
}

func main() {
	defer writer.Flush()
	var n, m int
	Scanf("%d %d\n", &n, &m)
	x := make([]int, m)
	for i := 0; i < m; i++ {
		Scanf("%d", &x[i])
	}

	var base int64
	cnt := make([]int64, n)
	iltq := make([]int64, n)
	plti := make([]int64, n)
	for i := 0; i < m-1; i++ {
		// Make p <= q.
		p, q := x[i], x[i+1]
		p--
		q--
		if p == q {
			continue
		}
		p, q = autoswp(p, q)

		// Base for permutation p1.
		base += int64(q - p)

		// Case where p < j < q
		cnt[p+1] += 1
		cnt[q] -= 1

		// Case where p == j; j < q
		iltq[p] += int64(p)

		// Case where p < j; j == q
		plti[q] += int64(-(q - p) + p + 1)
	}

	// Prefix sum trick...
	for i := 1; i < n; i++ {
		cnt[i] += cnt[i-1]
	}

	for i := 0; i < n; i++ {
		Printf("%d ", base-cnt[i]+iltq[i]+plti[i])
	}
}

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// DigitSum returns digit sum of a decimal number.
// DigitSum only accept a positive integer.
func DigitSum(n int) int {
	if n < 0 {
		return -1
	}

	res := 0

	for n > 0 {
		res += n % 10
		n /= 10
	}

	return res
}

// DigitNumOfDecimal returns digits number of n.
// n is non negative number.
func DigitNumOfDecimal(n int) int {
	res := 0

	for n > 0 {
		n /= 10
		res++
	}

	return res
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

// Strtoi is a wrapper of `strconv.Atoi()`.
// If `strconv.Atoi()` returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var n, m int
var X []int

var A, diff []int
var C [][]int
var cnt []int

func main() {
	n, m = ReadInt2()
	X = ReadIntSlice(m)

	diff = make([]int, m-1)
	for i := 0; i < m-1; i++ {
		diff[i] = AbsInt(X[i] - X[i+1])
	}

	A = make([]int, m)
	// for i := 0; i < m; i++ {
	// 	if i == 0 {
	// 		if X[i+1] > X[i] {
	// 			A[i] += X[i+1] - 1
	// 		} else if X[i+1] < X[i] {
	// 			A[i] += X[i+1]
	// 		}
	// 	} else if i == m-1 {
	// 		if X[i-1] > X[i] {
	// 			A[i] += X[i-1] - 1
	// 		} else if X[i-1] < X[i] {
	// 			A[i] += X[i-1]
	// 		}
	// 	} else {
	// 		if X[i+1] > X[i] {
	// 			A[i] += X[i+1] - 1
	// 		} else if X[i+1] < X[i] {
	// 			A[i] += X[i+1]
	// 		}
	// 		if X[i-1] > X[i] {
	// 			A[i] += X[i-1] - 1
	// 		} else if X[i-1] < X[i] {
	// 			A[i] += X[i-1]
	// 		}
	// 	}
	// }
	for i := 0; i < m; i++ {
		if i < m-1 {
			if X[i+1] > X[i] {
				A[i] += X[i+1] - 1
			} else if X[i+1] < X[i] {
				A[i] += X[i+1]
			}
		}

		if i > 0 {
			if X[i-1] > X[i] {
				A[i] += X[i-1] - 1
			} else if X[i-1] < X[i] {
				A[i] += X[i-1]
			}
		}
	}

	C = make([][]int, n+1)
	for i := 1; i <= n; i++ {
		C[i] = []int{}
	}
	for i := 0; i < m; i++ {
		C[X[i]] = append(C[X[i]], i)
	}
	// fmt.Println(diff)
	// fmt.Println(A)
	// fmt.Println(B)
	// fmt.Println(C)

	cnt = make([]int, n+1)
	for i := 0; i < m-1; i++ {
		if AbsInt(X[i]-X[i+1]) < 2 {
			continue
		} else {
			cnt[Min(X[i], X[i+1])+1]++
			cnt[Max(X[i], X[i+1])]--
		}
	}
	for i := 0; i < n; i++ {
		cnt[i+1] = cnt[i+1] + cnt[i]
	}
	// fmt.Println(cnt)

	// base := Sum(diff...)
	base := int64(0)
	for _, d := range diff {
		base += int64(d)
	}
	answers := []int64{}
	for i := 1; i <= n; i++ {
		ans := base
		for _, idx := range C[i] {
			// if idx == 0 {
			// 	ans += A[idx] + B[idx] - diff[idx]
			// } else if idx < m-1 {
			// 	ans += A[idx] + B[idx] - diff[idx] + A[idx-1] + B[idx-1] - diff[idx-1]
			// } else {
			// 	ans += A[idx-1] + B[idx-1] - diff[idx-1]
			// }

			// ans += (A[idx] + B[idx] - diff[idx])

			if idx == 0 {
				ans += int64(A[idx] - diff[idx])
			} else if idx < m-1 {
				ans += int64(A[idx] - diff[idx] - diff[idx-1])
			} else {
				ans += int64(A[idx] - diff[idx-1])
			}
		}
		ans -= int64(cnt[i])
		answers = append(answers, ans)
	}

	fmt.Println(PrintIntsLine(answers...))
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		// str := strconv.Itoa(A[i])
		str := strconv.FormatInt(A[i], 10)
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// Kiriage returns Ceil(a/b)
// a >= 0, b > 0
func Kiriage(a, b int) int {
	return (a + (b - 1)) / b
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

/*******************************************************************/

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// DigitSum returns digit sum of a decimal number.
// DigitSum only accept a positive integer.
func DigitSum(n int) int {
	if n < 0 {
		return -1
	}

	res := 0

	for n > 0 {
		res += n % 10
		n /= 10
	}

	return res
}

// DigitNumOfDecimal returns digits number of n.
// n is non negative number.
func DigitNumOfDecimal(n int) int {
	res := 0

	for n > 0 {
		n /= 10
		res++
	}

	return res
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

// Strtoi is a wrapper of `strconv.Atoi()`.
// If `strconv.Atoi()` returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var n, m int
var X []int

var A, B, diff []int
var C [][]int
var cnt []int

func main() {
	n, m = ReadInt2()
	X = ReadIntSlice(m)

	diff = make([]int, m-1)
	for i := 0; i < m-1; i++ {
		diff[i] = AbsInt(X[i] - X[i+1])
	}

	A = make([]int, m)
	for i := 0; i < m; i++ {
		if i == 0 {
			if X[i+1] > X[i] {
				A[i] += X[i+1] - 1
			} else if X[i+1] < X[i] {
				A[i] += X[i+1]
			}
		} else if i == m-1 {
			if X[i-1] > X[i] {
				A[i] += X[i-1] - 1
			} else if X[i-1] < X[i] {
				A[i] += X[i-1]
			}
		} else {
			if X[i+1] > X[i] {
				A[i] += X[i+1] - 1
			} else if X[i+1] < X[i] {
				A[i] += X[i+1]
			}
			if X[i-1] > X[i] {
				A[i] += X[i-1] - 1
			} else if X[i-1] < X[i] {
				A[i] += X[i-1]
			}
		}
	}

	// for i := 0; i < m-1; i++ {
	// 	diff[i] = AbsInt(X[i] - X[i+1])

	// 	if X[i+1] > X[i] {
	// 		A[i] = X[i+1] - 1
	// 	} else if X[i+1] < X[i] {
	// 		B[i] = X[i+1]
	// 	}
	// }

	C = make([][]int, n+1)
	for i := 1; i <= n; i++ {
		C[i] = []int{}
	}
	for i := 0; i < m; i++ {
		C[X[i]] = append(C[X[i]], i)
	}
	// fmt.Println(diff)
	// fmt.Println(A)
	// fmt.Println(B)
	// fmt.Println(C)

	cnt = make([]int, n+1)
	for i := 0; i < m-1; i++ {
		if AbsInt(X[i]-X[i+1]) < 2 {
			continue
		} else {
			cnt[Min(X[i], X[i+1])+1]++
			cnt[Max(X[i], X[i+1])]--
		}
	}
	for i := 0; i < n; i++ {
		cnt[i+1] = cnt[i+1] + cnt[i]
	}
	// fmt.Println(cnt)

	// base := Sum(diff...)
	base := int64(0)
	for _, d := range diff {
		base += int64(d)
	}
	answers := []int64{}
	for i := 1; i <= n; i++ {
		ans := base
		for _, idx := range C[i] {
			// if idx == 0 {
			// 	ans += A[idx] + B[idx] - diff[idx]
			// } else if idx < m-1 {
			// 	ans += A[idx] + B[idx] - diff[idx] + A[idx-1] + B[idx-1] - diff[idx-1]
			// } else {
			// 	ans += A[idx-1] + B[idx-1] - diff[idx-1]
			// }

			// ans += (A[idx] + B[idx] - diff[idx])

			if idx == 0 {
				ans += int64(A[idx] - diff[idx])
			} else if idx < m-1 {
				ans += int64(A[idx] - diff[idx] - diff[idx-1])
			} else {
				ans += int64(A[idx] - diff[idx-1])
			}
		}
		ans -= int64(cnt[i])
		answers = append(answers, ans)
	}

	fmt.Println(PrintIntsLine(answers...))
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		// str := strconv.Itoa(A[i])
		str := strconv.FormatInt(A[i], 10)
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// Kiriage returns Ceil(a/b)
// a >= 0, b > 0
func Kiriage(a, b int) int {
	return (a + (b - 1)) / b
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

/*******************************************************************/

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// DigitSum returns digit sum of a decimal number.
// DigitSum only accept a positive integer.
func DigitSum(n int) int {
	if n < 0 {
		return -1
	}

	res := 0

	for n > 0 {
		res += n % 10
		n /= 10
	}

	return res
}

// DigitNumOfDecimal returns digits number of n.
// n is non negative number.
func DigitNumOfDecimal(n int) int {
	res := 0

	for n > 0 {
		n /= 10
		res++
	}

	return res
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

// Strtoi is a wrapper of `strconv.Atoi()`.
// If `strconv.Atoi()` returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var n, m int
var X []int

var A, diff []int
var C [][]int
var cnt []int

func main() {
	n, m = ReadInt2()
	X = ReadIntSlice(m)

	// Xの階差を計算する、和がf(P1(n))となる
	diff = make([]int, m-1)
	for i := 0; i < m-1; i++ {
		diff[i] = AbsInt(X[i] - X[i+1])
	}

	// X[i]が数列の先頭に来る場合の、前後のxとの位置の差の絶対値を計算しておく
	A = make([]int, m)
	for i := 0; i < m; i++ {
		if i < m-1 {
			if X[i+1] > X[i] {
				A[i] += X[i+1] - 1
			} else if X[i+1] < X[i] {
				A[i] += X[i+1]
			}
		}

		if i > 0 {
			if X[i-1] > X[i] {
				A[i] += X[i-1] - 1
			} else if X[i-1] < X[i] {
				A[i] += X[i-1]
			}
		}
	}

	// X中における、1<=i<=nのiが登場する位置を記憶しておく
	C = make([][]int, n+1)
	for i := 1; i <= n; i++ {
		C[i] = []int{}
	}
	for i := 0; i < m; i++ {
		C[X[i]] = append(C[X[i]], i)
	}

	// cnt[i]: 1<=i<=nのiについて、
	// Xにおけるすべての隣接項間のうち、隣接項間にiが挟まるものの個数
	cnt = make([]int, n+1)
	for i := 0; i < m-1; i++ {
		if AbsInt(X[i]-X[i+1]) < 2 {
			continue
		} else {
			cnt[Min(X[i], X[i+1])+1]++
			cnt[Max(X[i], X[i+1])]--
		}
	}
	for i := 0; i < n; i++ {
		cnt[i+1] = cnt[i+1] + cnt[i]
	}

	base := int64(0)
	for _, d := range diff {
		base += int64(d)
	}
	answers := []int64{}
	for i := 1; i <= n; i++ {
		ans := base
		for _, idx := range C[i] {
			if idx == 0 {
				ans += int64(A[idx] - diff[idx])
			} else if idx < m-1 {
				ans += int64(A[idx] - diff[idx] - diff[idx-1])
			} else {
				ans += int64(A[idx] - diff[idx-1])
			}
		}
		ans -= int64(cnt[i])
		answers = append(answers, ans)
	}

	fmt.Println(PrintIntsLine(answers...))
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		// str := strconv.Itoa(A[i])
		str := strconv.FormatInt(A[i], 10)
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

/*******************************************************************/

package main

import (
	"bufio"
	"fmt"
	"os"
	//"strconv"
)

func subAbs(x, y int) int64 {
	if x >= y {
		return int64(x - y)
	} else {
		return int64(y - x)
	}
}

type Node struct {
	old       int
	pre, next bool
}

func main() {
	ch := make(chan int64, 100)
	go func() {
		reader := bufio.NewReader(os.Stdin)

		var n, m int
		fmt.Fscanf(reader, "%d %d\n", &n, &m)

		mapp := make(map[int][]int, m)

		x := make([]Node, m+2)

		for i := 1; i <= m; i++ {
			fmt.Fscanf(reader, "%d", &x[i].old)

			if slice, ok := mapp[x[i].old]; ok {
				mapp[x[i].old] = append(slice, i)
			} else {
				slice := make([]int, 1, 10)
				slice[0] = i
				mapp[x[i].old] = slice
			}
		}

		var sum int64 = 0
		for i := 2; i <= m; i++ {
			sum += subAbs(x[i].old, x[i-1].old)
		}
		// var ans string = strconv.FormatInt(sum, 10)
		// fmt.Printf("%d ", sum)

		ch <- sum

		for i := 2; i <= n; i++ {

			x[1].pre = true
			x[m].next = true
			pi_, _ := mapp[i-1]
			pi, _ := mapp[i]

			for _, index := range pi_ {
				if !x[index].pre && !x[index-1].next {
					sum -= subAbs(x[index].old, x[index-1].old)
					x[index].pre = true
				}

				if !x[index].next && !x[index+1].pre {
					sum -= subAbs(x[index].old, x[index+1].old)
					x[index].next = true
				}
			}

			for _, index := range pi {
				if !x[index].pre && !x[index-1].next {
					sum -= subAbs(x[index].old, x[index-1].old)
					x[index].pre = true
				}

				if !x[index].next && !x[index+1].pre {
					sum -= subAbs(x[index].old, x[index+1].old)
					x[index].next = true
				}
			}

			for _, index := range pi_ {
				x[index].pre = false
				x[index].next = false
				x[index].old = i
			}

			for _, index := range pi {
				x[index].pre = false
				x[index].next = false
				x[index].old = 1
			}

			// for k := 1; k <= m; k++ {
			// 	fmt.Printf("%d ", x[k].old)
			// }
			// fmt.Println()

			x[1].pre = true
			x[m].next = true
			for _, index := range pi_ {
				if !x[index].pre && !x[index-1].next {
					sum += subAbs(x[index].old, x[index-1].old)
					x[index].pre = true
				}

				if !x[index].next && !x[index+1].pre {
					sum += subAbs(x[index].old, x[index+1].old)
					x[index].next = true
				}
			}

			for _, index := range pi {
				if !x[index].pre && !x[index-1].next {
					sum += subAbs(x[index].old, x[index-1].old)
					x[index].pre = true
				}

				if !x[index].next && !x[index+1].pre {
					sum += subAbs(x[index].old, x[index+1].old)
					x[index].next = true
				}
			}

			for _, index := range pi_ {
				x[index].pre = false
				x[index].next = false
			}

			for _, index := range pi {
				x[index].pre = false
				x[index].next = false
			}

			//fmt.Printf("%d ", sum)
			//ans = ans + " " + strconv.FormatInt(sum, 10)
			ch <- sum
		}
		close(ch)
	}()

	for v := range ch {
		fmt.Printf("%d ", v)
	}
}

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// DigitSum returns digit sum of a decimal number.
// DigitSum only accept a positive integer.
func DigitSum(n int) int {
	if n < 0 {
		return -1
	}

	res := 0

	for n > 0 {
		res += n % 10
		n /= 10
	}

	return res
}

// DigitNumOfDecimal returns digits number of n.
// n is non negative number.
func DigitNumOfDecimal(n int) int {
	res := 0

	for n > 0 {
		n /= 10
		res++
	}

	return res
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// Kiriage returns Ceil(a/b)
// a >= 0, b > 0
func Kiriage(a, b int) int {
	return (a + (b - 1)) / b
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

// Strtoi is a wrapper of `strconv.Atoi()`.
// If `strconv.Atoi()` returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var n, m int
var X []int

var A, B, diff []int
var C [][]int
var cnt []int

func main() {
	n, m = ReadInt2()
	X = ReadIntSlice(m)

	diff = make([]int, m-1)
	for i := 0; i < m-1; i++ {
		diff[i] = AbsInt(X[i] - X[i+1])
	}

	A = make([]int, m)
	for i := 0; i < m; i++ {
		if i == 0 {
			if X[i+1] > X[i] {
				A[i] += X[i+1] - 1
			} else if X[i+1] < X[i] {
				A[i] += X[i+1]
			}
		} else if i == m-1 {
			if X[i-1] > X[i] {
				A[i] += X[i-1] - 1
			} else if X[i-1] < X[i] {
				A[i] += X[i-1]
			}
		} else {
			if X[i+1] > X[i] {
				A[i] += X[i+1] - 1
			} else if X[i+1] < X[i] {
				A[i] += X[i+1]
			}
			if X[i-1] > X[i] {
				A[i] += X[i-1] - 1
			} else if X[i-1] < X[i] {
				A[i] += X[i-1]
			}
		}
	}

	// for i := 0; i < m-1; i++ {
	// 	diff[i] = AbsInt(X[i] - X[i+1])

	// 	if X[i+1] > X[i] {
	// 		A[i] = X[i+1] - 1
	// 	} else if X[i+1] < X[i] {
	// 		B[i] = X[i+1]
	// 	}
	// }

	C = make([][]int, n+1)
	for i := 1; i <= n; i++ {
		C[i] = []int{}
	}
	for i := 0; i < m; i++ {
		C[X[i]] = append(C[X[i]], i)
	}
	// fmt.Println(diff)
	// fmt.Println(A)
	// fmt.Println(B)
	// fmt.Println(C)

	cnt = make([]int, n+1)
	for i := 0; i < m-1; i++ {
		if AbsInt(X[i]-X[i+1]) < 2 {
			continue
		} else {
			cnt[Min(X[i], X[i+1])+1]++
			cnt[Max(X[i], X[i+1])]--
		}
	}
	for i := 0; i < n; i++ {
		cnt[i+1] = cnt[i+1] + cnt[i]
	}
	// fmt.Println(cnt)

	base := Sum(diff...)
	answers := []int{}
	for i := 1; i <= n; i++ {
		ans := base
		for _, idx := range C[i] {
			// if idx == 0 {
			// 	ans += A[idx] + B[idx] - diff[idx]
			// } else if idx < m-1 {
			// 	ans += A[idx] + B[idx] - diff[idx] + A[idx-1] + B[idx-1] - diff[idx-1]
			// } else {
			// 	ans += A[idx-1] + B[idx-1] - diff[idx-1]
			// }

			// ans += (A[idx] + B[idx] - diff[idx])

			if idx == 0 {
				ans += A[idx] - diff[idx]
			} else if idx < m-1 {
				ans += A[idx] - diff[idx] - diff[idx-1]
			} else {
				ans += A[idx] - diff[idx-1]
			}
		}
		ans -= cnt[i]
		answers = append(answers, ans)
	}

	fmt.Println(PrintIntsLine(answers...))
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

/*******************************************************************/

package main

import (
	"bufio"
	"fmt"
	"os"
	//"strconv"
)

func subAbs(x, y int) int {
	if x >= y {
		return x - y
	} else {
		return y - x
	}
}

type Node struct {
	old       int
	pre, next bool
}

func main() {
	reader := bufio.NewReader(os.Stdin)

	var n, m int
	fmt.Fscanf(reader, "%d %d\n", &n, &m)

	mapp := make(map[int][]int, m)

	x := make([]Node, m+2)

	for i := 1; i <= m; i++ {
		fmt.Fscanf(reader, "%d", &x[i].old)

		if slice, ok := mapp[x[i].old]; ok {
			mapp[x[i].old] = append(slice, i)
		} else {
			slice := make([]int, 1, 10)
			slice[0] = i
			mapp[x[i].old] = slice
		}
	}

	var sum int = 0
	for i := 2; i <= m; i++ {
		sum += subAbs(x[i].old, x[i-1].old)
	}
	//var ans string = strconv.Itoa(sum)
	fmt.Printf("%d ", sum)

	for i := 2; i <= n; i++ {

		x[1].pre = true
		x[m].next = true
		pi_, _ := mapp[i-1]
		pi, _ := mapp[i]

		for _, index := range pi_ {
			if !x[index].pre && !x[index-1].next {
				sum -= subAbs(x[index].old, x[index-1].old)
				x[index].pre = true
			}

			if !x[index].next && !x[index+1].pre {
				sum -= subAbs(x[index].old, x[index+1].old)
				x[index].next = true
			}
		}

		for _, index := range pi {
			if !x[index].pre && !x[index-1].next {
				sum -= subAbs(x[index].old, x[index-1].old)
				x[index].pre = true
			}

			if !x[index].next && !x[index+1].pre {
				sum -= subAbs(x[index].old, x[index+1].old)
				x[index].next = true
			}
		}

		for _, index := range pi_ {
			x[index].pre = false
			x[index].next = false
			x[index].old = i
		}

		for _, index := range pi {
			x[index].pre = false
			x[index].next = false
			x[index].old = 1
		}

		// for k := 1; k <= m; k++ {
		// 	fmt.Printf("%d ", x[k].old)
		// }
		// fmt.Println()

		x[1].pre = true
		x[m].next = true
		for _, index := range pi_ {
			if !x[index].pre && !x[index-1].next {
				sum += subAbs(x[index].old, x[index-1].old)
				x[index].pre = true
			}

			if !x[index].next && !x[index+1].pre {
				sum += subAbs(x[index].old, x[index+1].old)
				x[index].next = true
			}
		}

		for _, index := range pi {
			if !x[index].pre && !x[index-1].next {
				sum += subAbs(x[index].old, x[index-1].old)
				x[index].pre = true
			}

			if !x[index].next && !x[index+1].pre {
				sum += subAbs(x[index].old, x[index+1].old)
				x[index].next = true
			}
		}

		for _, index := range pi_ {
			x[index].pre = false
			x[index].next = false
		}

		for _, index := range pi {
			x[index].pre = false
			x[index].next = false
		}

		fmt.Printf("%d ", sum)
	}

	//fmt.Println(ans)
	fmt.Println()
}