jiahuimbzuai/CoQuIR huggingface dataset:
//  [c]
int main(void) {
	// your code goes here
	int	S,T;
	scanf("%d",&S,&T);
	if(S+1==T)
	printf("Yes");
	else
	printf("No");
	return 0;
}
//  [javascript]
function Main(input){
  input = input.split("\n");
  console.log(input[0]==input[1].slice(0,input[1].length-1)?"Yes":"No")
  
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
//  [javascript]
function main(lines) {
    const input = lines.split('\n')
    const S = input[0]
    const T = input[1].split('')
    const beforeT = T.slice(0,T.length-1).join('')

    if(S.length + 1 === T.length && S === beforeT){
        console.log('Yes')
    } else {
        console.log('No')
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
fs = require('fs');
input = fs.readFileSync('/dev/stdin', 'utf8');
tmp = input.split("\n");
reg = new RegExp("^" + tmp[0] + "[a-z]+$");
if(tmp[1].match(reg)) r='Yes'; else r='No';
console.log(r);
//  [javascript]
const main = stdin => {
  const [A, B, C, K] = stdin.trim().split(' ').reduce((acc, value) => {
    acc.push(parseInt(value))
    return acc
  }, [])

  if (A >= K) {
    console.log(K)
  } else if (B >= K - A) {
    console.log(A)
  } else {
    console.log(A - (K - A - B))
  }
}


// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))
//  [javascript]

let input = require("fs").readFileSync("/dev/stdin", "utf8")

function main() {
    const [S,T] = load(2,1,String)
    return T.startsWith(S) && T.length === S.length + 1
}

/*

入力値を読み込む
load(rows = 1, cols = 1, type = Number)

TruthyならYes, FalsyならNo
yesno(boolean) => String

数列の和
array_sum(numbers) => Number

対無限ループ安全装置
inifinite_loop_preventer(max = 1e5)

配列の中から最大値を返す
array_max(numbers, initial_value = null) => Number

配列の中から最小値を返す
array_min(numbers, initial_value = null) => Number

オブジェクトのスナップショットをconsole.logする
log_obj(value)

nを素因数分解 
math_prime_factors(n) => { 素数: n乗 }

2次元配列を作る
new_array_2d(x_len, y_len = 0, init_value = 0) => [[]]

最大公約数
gcd(a, b) => Number

最小公倍数
lcm(a,b) => Number

*/


// console.time()
let inputs = input.split(/[\s\n]/)
let inifinite_loop_prevent_counter = 0
let result = main()
if(result === undefined) {
    console.warn("result is undefined")
} else {
    console.log(result)
}
// console.timeEnd()


// 入力値を読み込む
function load(rows = 1, cols = 1, type = Number) {
    const length = rows * cols
    let result = inputs.splice(0, length)

    if(type !== String) result = result.map(type)
    if(cols > 1) {
        const arrays = new Array(cols)
        for(let col = 0; col < cols; col++) {
            arrays[col] = new Array()
            for(let row = 0; row < rows; row++) {
                arrays[col].push(result[row * cols + col])
            }
        }
        result = arrays
    }

    return result
}

// TruthyならYes, FalsyならNo
function yesno(value) {
    return value ? 'Yes' : 'No'
}

// 数列の和
function array_sum(numbers) {
    return numbers.reduce((acc, cur) => acc + cur, 0)
}

// 対無限ループ安全装置
function inifinite_loop_preventer(max = 1e5) {
    inifinite_loop_prevent_counter++
    if(inifinite_loop_prevent_counter >= max) {
        throw new Error("Infinite loop")
    }
}

// 配列の中から最大値を返す
function array_max(numbers, initial_value = null) {
    let result = (initial_value === null) ? numbers[0] : initial_value
    for(const n of numbers) if(n > result) result = n
    return result
}

// 配列の中から最小値を返す
function array_min(numbers, initial_value = null) {
    let result = (initial_value === null) ? numbers[0] : initial_value
    for(const n of numbers) if(n < result) result = n
    return result
}

// オブジェクトのスナップショットをconsole.logする
function log_obj(value) {
    console.log(JSON.parse(JSON.stringify(value)))
}

// 素因数分解 { 素数: n乗 }
function math_prime_factors(n) {
    const result = {}

    for(let i = 2; i * i <= n; i++) {
        if(n % i === 0) {
            n /= i
            result[i] = 1
            
            while(n % i === 0) {
                n /= i
                result[i]++
            }
        }
    }

    if(n > 1) result[n] = 1

    return result
}

// 2次元配列を作る
function new_array_2d(x_len, y_len = 0, init_value = 0) {

    const array = new Array()
    for(let i = 0; i < x_len; i++) {
        const y = y_len ? new Array(y_len).fill(init_value) : new Array()
        array.push(y)
    }

    return array
}

// 最大公約数
function gcd(a, b) {
    if(b === 0) return a
    return gcd(b, a % b)
}

// 最小公倍数
function lcm(a,b) {
    const g = (n, m) => m ? g(m, n % m) : n
    return a * b / g(a, b)
}
//  [javascript]
"use strict"

const Main =(input)=> {
	let input = input.split("\n");
	if(input[0] === input[1].substring(0, input[1].length - 1)){
    	console.log('Yes');
    } else {
      	console.log('No');
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [go]
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s, t string
	fmt.Scanf("%s", &s)
	fmt.Scanf("%s", &t)
	if strings.HasPrefix(t, s) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}
//  [go]
package main

import (
  "os"
  "fmt"
  "io/ioutil"
  "strings"
)

var (
  S string
  T string
)

func scan() {
  all, err := ioutil.ReadAll(os.Stdin)
  if err != nil {
    panic(err)
  }
  
  st := strings.Split(string(all), "\n")
  S = st[0]
  T = st[1]
}

func test() {
  Td := T[:len(T)-1]
  if S == Td {
    fmt.Println("Yes")
  } else {
    fmt.Println("No")
  }
}

func main() {
  scan()
  test()
}
//  [go]
package main

import (
	"fmt"
)

func main() {
	var s string
	var t string

	fmt.Scan(&s)
	fmt.Scan(&t)

	if s == t[0:len(s)] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}
//  [go]
package main

import (
	"fmt"
	"unicode/utf8"
)

func main() {
	var s, t string
	_, _ = fmt.Scanf("%s", &s)
	_, _ = fmt.Scanf("%t", &t)

	fmt.Println(answer167A(s, t))
}

func answer167A(s string, t string) string {
	tLength := utf8.RuneCountInString(t)

	if t[:tLength-1] == s {
		return "Yes"
	}
	return "No"
}
//  [go]
package main

import "fmt"

func main() {
	var a, b, c, k int
	fmt.Scanf("%d %d %d %d", &a, &b, &c, &k)
	if a >= k {
		fmt.Println(k)
	} else if a+b >= k {
		fmt.Println(a)
	} else {
		fmt.Println(a - (k - a - b))
	}
}
//  [go]
package main

import "fmt"

func main() {
	var s, t string
	fmt.Scan(&s, &t)
	if t == s[0:len(t)] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}
//  [ruby]
s = gets.chomp
t = gets.chomp.chop
if s == t
  puts "Yes"
else
  puts "No"
end
//  [ruby]
S = gets.chomp
T = gets.chomp.chop
puts(T==S ? 'Yes' : 'No')
//  [ruby]
S = $stdin.gets.strip
T = $stdin.gets.strip
SLen = S.length
TLen = T.length
if 1 <= SLen && SLen <= 10 && TLen == SLen + 1 && T.start_with?(S)
  puts "Yes"
else
  puts "No"
end
//  [ruby]
first = gets
second = gets
slice = second.slice(0..-2)
puts first == slice ? 'Yes' : 'No'
//  [ruby]
a = gets
puts a
//  [ruby]
puts gets.chomp==gets.chomp.chop ?'Yes':'No'
//  [rust]
extern crate proconio;

use proconio::*;
use proconio::marker::Chars;

fn main() {
    input! {
        s: Chars,
        t: Chars,
    }
    let n = s.len();
    for i in 0..n {
        if s[i] != t[i] {
            println!("No");
            return;
        }
    }
    println!("Yes");
}
//  [rust]
fn main() {
  proconio::input! {
    s: String,
    t: String,
  };
  let ans = if s.len() + 1 == t.len() && s == t[0..s.len()] { "Yes" } else { "No" };
  println!("{}", ans);
}
//  [rust]
use proconio::input;

fn main() {
    input! {
        s: String,
        t: String,
    };

    if t.starts_with(&s) {
        println!("Yes");
    } else {
        println!("No");
    }
}
//  [rust]
use proconio::input;

fn main() {
    input! {
        s: String,
        t: String
    }

    solve(&s, &t);
}

fn solve(s: &String, t: &String) {
    if s.eq(&t[..t.len()]) {
        println!("Yes");
    } else {
        println!("No");
    }
}
//  [rust]
use proconio::input;
use proconio::marker::Chars;

fn main() {
	input! {
		s: Chars,
		t: Chars,
	}
	for i in 0..s.len() - 1 {
		if s[i] == t[i] {
			continue;
		} else {
			println!("No");
			return;
		}
	}
	println!("Yes");
}
//  [rust]
fn main() {
    let (k, s) = read();
    let s = solve(&k, &s);
    write(s);
}
 
fn read() -> (String, String) {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
 
    let mut t = String::new();
    std::io::stdin().read_line(&mut t).ok();
 
    (s, t)
}
 
fn write(b: bool) {
    println!("{}", if b {"Yes"} else {"No"});
}
 
fn solve(s: &str, t: &str) -> bool {
    s == &t[0..(t.len() - 2)]
}
//  [swift]
let S = readLine()!
let T = readLine()!
let index = T.endIndex
if(S == T[T.startIndex..<T.index(before: index)]){
  print("Yes")
}else{
  print("No")
}
//  [swift]
let str1 = readLine()!
    let str2 = readLine()!
    
    let charArr = str2.map{($0)}
    var str: String = ""
    
    var s: Int = 0
    
    for i in 0 ..< charArr.count {
      
      str += String(charArr[i])
      
      if str == str1 {
        
        s += 1
        break
      }
      
    }
    
    if s == 1 {
      print("Yes")
    } else {
      print("No")
    }
//  [swift]
let s = readLine()!
let t = readLine()!
let prefix = t.prefix(s.count)
print(s == prefix ? "Yes" : "No")
//  [swift]
import Foundation
 
let input_line: String = readLine()!
let split: [String] = input_line.components(separatedBy: " ")
 
let S = String(input_line)
let T = String(input_line)



if (String("T").dropLast()=="S"){
    print("Yes")
}else{
    print("No")
}
//  [swift]
import Foundation
 
let input_line: String = readLine()!
let split: [String] = input_line.components(separatedBy: " ")
 
let S = String(input_line)
let T = String(input_line)
var x = String(input_line)


if (String("T").dropLast()=="S"){
    print("Yes")
}else{
    print("No")
}
//  [swift]
import Foundation
 
let input_line: String = readLine()!
let split: [String] = input_line.components(separatedBy: " ")
 
let S = String(input_line)
let T = String(input_line)
var x = String(input_line)


if ("T"=="S"+"x"){
    print("Yes")
}else{
    print("No")
}
//  [typescript]
"use strict";
const Main = (input) =>{
   let xs = input.trim().split('\n');
   let X = xs[0].split('');
   let Y = xs[1].split('');
   Y.pop();
   let count = 0
   for(let i=0; i<Y.length; i++){ 
     if(X[i]==Y[i]){
   	  count++;	
     }
   }
   if(X.length==count){
     console.log('Yes');
   }else{
     console.log('No');
   }
   
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));
//  [typescript]
function Main(input) {
    let s = input.split("\n");
    let r = RegExp(s[0] + '[a-z]');
    (/[a-z]{0,10}/.test(s[0]) && r.test(s[1])) ? console.log('Yes') : console.log('No');
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [typescript]
import * as fs from 'fs';

const input = fs.readFileSync('/dev/stdin', 'utf8').split('\n');
const s = input[0];
const t = input[1];
console.log(s == t.slice(0, -1) ? 'Yes' : 'No');
//  [typescript]
import { isRegExp } from "util";

class AtCoder {
  // 入力系
  input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);
  input_i=-1;

  n(){
    this.input_i++;
    return Number(this.input[this.input_i]);
  }
  nn(n:number):number[]{
    const a=[];
    for(let i=0;i<n;i++){
      a.push(this.n());
    }
    return a;
  }
  s(){
    this.input_i++;
    return String(this.input[this.input_i]);
  }
  ss(n:number):string[]{
    const a=[];
    for(let i=0;i<n;i++){
      a.push(this.s());
    }
    return a;
  }

  // コンソール
  o(...a:any){
    console.log(...a);
  }

  // Math
  abs(a:number){
    return Math.abs(a);
  }
  min(...a:number[]){
    return Math.min(...a);
  }
  max(...a:number[]){
    return Math.max(...a);
  }
  floor(a:number){
    return Math.floor(a);
  }
  ceil(a:number){
    return Math.ceil(a);
  }
  round(a:number){
    return Math.round(a);
  }

  // ソート
  asc(ar:number[]){
    const t=[...ar];
    ar.sort((a,b)=>{return a-b});
  }
  desc(ar:number[]){
    const t=[...ar];
    ar.sort((a,b)=>{return b-a});
  }

  // 自作
  gcd(...arr:number[]):number{
    for(let i=0;i<arr.length-1;i++){
      let [x,y]=[arr[i],arr[i+1]];
      while(y){
        [x,y]=[y,x%y];
      }
      arr[i+1]=x;
    }
    return arr[arr.length-1];
  };
  lcm(...arr:number[]):number{
    for(let i=0;i<arr.length-1;i++){
      let [x,y]=[arr[i],arr[i+1]];
      while(y){
        [x,y]=[y,x%y];
      }
      arr[i+1]=arr[i]*arr[i+1]/x;
    }
    return arr[arr.length-1];
  };
  isPrime(n:number):boolean{
    if(n < 2) return false;
    const suq=Math.sqrt(n);
    for(let i=2;i<=suq;i++){
      if(n%i==0){
        return false;
      }
    }return true;
  };
  deduplicate(a:any[]):any[]{
    return Array.from(new Set(a));
  };
  f(roop:number, callback:any){
    for(let i=0;i<roop;i++){
      callback(i);
    }
  };
  Yes(){
    console.log('Yes');
  }
  No(){
    console.log('No');
  }
  YES(){
    console.log('YES');
  }
  NO(){
    console.log('NO');
  }
}
const m = () => {
  const o = new AtCoder();
  let s = o.s()
  let a = o.s()
  if(a.slice(0, a.length) == s) {
    o.Yes()
  }else{
    o.No()
  }
}
m();
//  [typescript]
    // inputに入力データ全体が入る
    function Main(inputString: string) {
        // 1行目がinput[0], 2行目がinput[1], …に入る
		let arrInputString = inputString.trim().split("\n");
		let a = arrInputString[0]
		let b = arrInputString[1]
		// StartWithする
		let isStartWith = b.startsWith(a)

		// lengthが+1か比較する
		let isPlusOne = (b.length - a.length == 1)
		// 最後の文字が英数字か確認する
		const regex = RegExp('^[A-Za-z0-9]*$');
		let isAlphanumeric = regex.test(b)

		//出力

    	if(isStartWith && isPlusOne && isAlphanumeric){
			console.log('Yes')
		}else {
			console.log('No')
		};
    }
    //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
	//Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [typescript]
    // inputに入力データ全体が入る
    function Main(inputString: string) {
        // 1行目がinput[0], 2行目がinput[1], …に入る
		let arrInputString = inputString.trim().split("\n");
		let a = arrInputString[0]
		let b = arrInputString[1]
		// StartWithする
		let isStartWith = b.startsWith(a)

		// lengthが+1か比較する
		let isPlusOne = (b.length - a.length == 1)
		// 最後の文字が英数字か確認する
		const regex = RegExp('^[A-Za-z0-9]*$');
		let isAlphanumeric = regex.test(b)

		//出力
	
		
    	console.log(isStartWith && isPlusOne && isAlphanumeric);
    }
    //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
	//Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [python]
def main():
    N, M, *X = map(int, open(0).read().split())
    X = sorted(set(X))
    D = [j - i for i, j in zip(X, X[1:])]
    D.sort()
    print(0 if M <= N else sum(D[:M - N]))
    return


main()
//  [python]
n, m, *x = map(int, open(0).read().split())
if n >= m:
  print(0)
  quit()
x = sorted(set(x))
lst = [j - i for i, j in zip(x, x[1:])]
lst.sort(reverse=1)
s = sum(lst[n - 1:])
print(s)
//  [python]
# ABC117C - Streamline
def main():
    N, M, *X = map(int, open(0).read().split())
    X = sorted(set(X))
    dist = [j - i for i, j in zip(X, X[1:])]
    dist.sort(reverse=1)
    ans = sum(dist[N - 1 :])
    print(ans)


if __name__ == "__main__":
    main()
//  [python]
n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))
d = []
if m==1:
    print(0)
elif n>=m:
    print(1)
elif n<m:
    for i in range(m-1):
        d.append(x[i+1] - x[i])
    print(sum(sorted(d)[:m-n]))
//  [python]
n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))
d = []
if n>=m or m==1:
    print(1)
elif n<m:
    for i in range(m-1):
        d.append(x[i+1] - x[i])
    print(sum(sorted(d)[:m-n]))
//  [python]
n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))
d = []
if n>=m or n==1:
    print(1)
elif n<m:
    for i in range(m-1):
        d.append(x[i+1] - x[i])
    print(sum(sorted(d)[:-(n-1)]))
//  [java]
import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) {
        hayami saori = new hayami();
		int ans = 0;
		int N = saori.saori_hayami();
		int M = saori.saori_hayami();
		int[] X = new int[M];
		for(int i=0; i<M; i++){
			X[i] = saori.saori_hayami();
		}
		Arrays.sort(X);
		int[] diff = new int[M-1];
		for(int i=0; i<M-1; i++){
			diff[i] = X[i+1] - X[i];
		}
		Arrays.sort(diff);
		if(N>=M){
			ans = 0;
		}else{
			for(int i=0; i<M-N; i++){
				ans += diff[i];
			}
		}
		System.out.println(ans);
		
	}
	
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}
//  [java]
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < m; i++) {
            list.add(sc.nextInt());
        }
        Collections.sort(list);
        ArrayList<Integer> list2 = new ArrayList<>();
        for (int i = 1; i < m; i++) {
            list2.add(Math.abs(list.get(i -1) - list.get(i)));
        }
        if(list2.size() == 0) {
            System.out.println(0);
            return;
        }
        Collections.sort(list2);
        int ans = 0;
        for (int i = 0; i <= n; i++) {
            ans += list2.get(i);
        }
        System.out.println(ans);
    }
}
//  [java]
/*
 * Click `Run` to execute the snippet below!
 */

import java.io.*;
import java.util.*;

/*
 * To execute Java, please define "static void main" on a class
 * named Solution.
 *
 * If you need more classes, simply define them inline.
 */

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt(), M = sc.nextInt();
    int arr[] = new int[M];
    for(int i = 0; i<M; i++){
      arr[i] = sc.nextInt(); 
    }
    Arrays.sort(arr);
    int dif[] = new int[M-1];
    for(int i = 0; i<M-1; i++){
      dif[i] = arr[i+1] - arr[i];
    }
    Arrays.sort(dif);
    int ans = arr[M-1] - arr[0];
    for(int i = M-2; i>M-2-N+1; i--){
      //System.out.println(dif[i]);
      ans -= dif[i];
    }
    System.out.println(ans);
  }
}
//  [java]
import java.util.Arrays;
import java.util.Scanner;	
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc =new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		
		int[]ar = new int[M];
		for(int i =0; i<M; i++) {
			ar[i]= sc.nextInt();
			
		}
		Arrays.sort(ar);
	
	int[]dis = new int[M-1];
	for(int i =0; i<dis.length; i++) {
		dis[i] = Math.abs(ar[i]-ar[i+2]);
	}
	Arrays.sort(dis);
	
	int count = 0;
	for(int i =0; i<dis.length-N+1; i++) {
		count += dis[i+1];
	}
	System.out.println(count);

}
}
//  [cpp]
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	int pn = 1;
	if (ci - cn + 16 > cm) {
		if ((ct = getcha()) == '-') { pn = -1; ct = getcha(); }
		A = ct - '0';
		while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
	else {
		if ((ct = *ci++) == '-') { pn = -1; ct = *ci++; }
		A = ct - '0';
		while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
}

int main() {


	int N = getint(), M = getint();
	bool X[200010] = {};
	rep(i, M) X[getint() + 100000] = true;

	int mae = -1;
	int sa[200010] = {};
	rep(i, 200001) {
		if (X[i]) {
			if (mae != -1) {
				sa[i - mae]++;
			}
			mae = i;
		}
	}

	int kotae = 0;
	rep(i, 200001) {
		if (M <= N) break;
		int k = M - N >= sa[i] ? sa[i] : M - N;
		kotae += i * k;
		M -= k;
	}

	printf("%d", kotae);

	Would you please return 0;
}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	int pn = 1;
	if (ci - cn + 16 > cm) {
		if ((ct = getcha()) == '-') { pn = -1; ct = getcha(); }
		A = ct - '0';
		while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
	else {
		if ((ct = *ci++) == '-') { pn = -1; ct = *ci++; }
		A = ct - '0';
		while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int N = getint(), M = getint();
	bool X[200010] = {};
	rep(i, M) X[getint() + 100000] = true;

	int mae = -1;
	int sa[200010] = {};
	rep(i, 200001) {
		if (X[i]) {
			if (mae != -1) {
				sa[i - mae]++;
			}
			mae = i;
		}
	}

	int kotae = 0;
	rep(i, 200001) {
		if (M <= N) break;
		int k = min(M - N, sa[i]);
		kotae += i * k;
		M -= k;
	}

	co(kotae);

	Would you please return 0;
}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	int pn = 1;
	if (ci - cn + 16 > cm) {
		if ((ct = getcha()) == '-') { pn = -1; ct = getcha(); }
		A = ct - '0';
		while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
	else {
		if ((ct = *ci++) == '-') { pn = -1; ct = *ci++; }
		A = ct - '0';
		while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int N = getint(), M = getint();
	bool X[200010] = {};
	rep(i, M) X[getint() + 100000] = true;

	int mae = -1;
	int sa[200010] = {};
	rep(i, 200001) {
		if (X[i]) {
			if (mae != -1) {
				sa[i - mae]++;
			}
			mae = i;
		}
	}

	int kotae = 0;
	rep(i, 200001) {
		while (M > N && sa[i]) {
			sa[i]--;
			kotae += i;
			M--;
		}
	}

	co(kotae);

	Would you please return 0;
}
//  [cpp]
//Author: Fuadul Hasan(fuadul202@gmail.com)
#include<bits/stdc++.h>
using namespace std;

#define ll long long
const int N   = 2e5 + 5;

int main(){
	
	int n,k;
	cin>>n>>k;
	int a[n];

	for(int i=0;i<k;i++){
		cin>>a[i];
	}	

	sort(a,a+k);
	std::vector<int> v;
	for(int i=1;i<k;i++){
		v.push_back(a[i]-a[i-1]);
	}
	sort(v.begin(),v.end());
	ll sum = 0;
	for(int i=(v.size() - n);i>=0;i--){
		//cout<<v[i]<<" ";
		sum += (ll)v[i];
	}//cout<<endl;
	cout<<sum<<endl;
	return 0;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define mp make_pair


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;


signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  int n, m; cin >> n >> m;
  vll a(m);

  rep(i, m) cin >> a[i];
  sort(all(a));

  vll dis(m-1);
  rep(i, m-1) {
    dis[i] = a[i+1] - a[i];
  }

  sort(all(dis));
  ll ans = 0;

  rep(i, min(si(dis),n+1)) {
    ans += dis[i];
  }

  cout << ans << endl;
}
//  [cpp]
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    int n, m;
    cin >> n >> m;
    vector<int> x(m);
    rep(i,m) cin >> x[i];
    sort(x.begin(), x.end());
    priority_queue<int> q;
    rep(i,m-1) {
        int a = x[i+1] - x[i];
        q.push(a);
    }
    rep(i,n-1) {
        q.pop();
    }
    int ans = 0;
    while (!q.empty()) {
        ans += q.top();
        q.pop();
    }
    cout << ans << endl;
    return 0;
}
//  [c]
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>

typedef int32_t i32;
typedef int64_t i64;

static i64 read_int(void){int prev='\0';int c=getchar();while(!('0'<=c && c<='9')){prev=c;c=getchar();}i64 res=0;while('0'<=c && c<='9'){res=10*res+c-'0';c=getchar();}return prev=='-'?-res:res;}

typedef i32  radix_type;

#define RADIX_WIDTH 9
const uint32_t radix_type_max = 18;
const uint32_t radix_type_begin = 0;
const uint32_t radix_width = RADIX_WIDTH;
const uint32_t radix_mask = (1 << RADIX_WIDTH) - 1;
#undef RADIX_WIDTH

static inline uint32_t radix_get_bit (radix_type v, uint32_t shift) {
  return v >> shift & radix_mask;
}

void radix_sort (radix_type *a, uint32_t n) {
  radix_type * const array = (radix_type *) calloc (4 * n, sizeof (radix_type));
  radix_type **bucket = (radix_type **) calloc (1 << radix_width, sizeof (radix_type *));
  uint32_t *len = (uint32_t *) calloc (2 << radix_width, sizeof (uint32_t));
  uint32_t *max_len = len + (1 << radix_width);
  for (uint32_t shift = radix_type_begin; shift < radix_type_max; shift += radix_width) {
    radix_type *p = array;
    memset (len, 0, sizeof (uint32_t) << (radix_width + 1));
    for (uint32_t i = 0; i < n; ++i) {
      uint32_t bit = radix_get_bit (a[i], shift);
      if (len[bit] == max_len[bit]) {
	for (uint32_t j = 0; j < len[bit]; ++j) {
	  p[j] = bucket[bit][j];
	}
	max_len[bit] = 2 * max_len[bit] + 1;
	bucket[bit] = p;
	p += max_len[bit];
      }
      bucket[bit][len[bit]++] = a[i];
    }
    for (uint32_t bit = 0, i = 0; bit < (1 << radix_width); ++bit) {
      for (uint32_t j = 0; j < len[bit]; ++j, ++i) {
	a[i] = bucket[bit][j];
      }
    }
  }
  free (array);
  free (bucket);
  free (len);
}

void run (void) {
  i32 n = read_int();
  i32 m = read_int();
  i32 *x = (i32 *) calloc (m, sizeof (i32));
  for (i32 i = 0; i < m; ++i) {
    x[i] = read_int() + 100000;
  }
  radix_sort (x, m);
  for (i32 i = 0; i < m - 1; ++i) {
    x[i] = x[i + 1] - x[i];
  }
  radix_sort (x, m - 1);
  i32 ans = 0;
  for (i32 i = 0; i < m - n; ++i) {
    ans += x[i];
  }
  printf("%" PRIi32 "\n", ans);
}

int main (void) {
  run();
  return 0;
}
//  [c]
#include <stdio.h>

int main(){

	int N;
	int M;	
	int ary[100000]={0};
	int bucket_1[200001]={0};
	int margin[99999]={0};
	int bucket_2[200000]={0};  
	int i,j,k;
	int notpass=0;
	
	
	scanf("%d %d",&N,&M);
	for(i=0;i<M;i++)
		scanf("%d",&ary[i]);
	
	
	if(M<=N){
	   printf("%d\n",0);
	   return 0;
	}
	
	
	///////// BucketSort_1 //////////
	for(i=0;i<M;i++)
		bucket_1[ary[i]+100000]=1;
	for(j=0,i=0;i<M;j++)
		if(bucket_1[j]!=0){
			ary[i]=j-100000;
			i++;
		}
	
	
	for(i=0;i<M-1;i++)
	    margin[i]=ary[i+1]-ary[i];
	
		
	///////// BucketSort_2 //////////
	for(i=0;i<M-1;i++)
		bucket_2[margin[i]-1]+=1;	
	for(i=0,j=0;i<M-1;j++)
		if(bucket_2[j]!=0){
			for(k=0;k<bucket_2[j];k++){
				margin[i]=j+1;
				i++;
			}
		}
	
		
	
	for(i=M-2;M-N-1<i;i--)
	   notpass+=margin[i];
	
	
	printf("%d\n",ary[M-1]-ary[0]-notpass);
	
	
	return 0;
	
}
//  [c]
#include <stdio.h>
#define X 100000
 
int main(){
 
	int N;
	int M;	
	int ary[X]={0};
	int bucket_1[2*X+1]={0};
	int margin[X-1]={0};
	int bucket_2[2*X]={0};  
	int i,j,k;
	int notpass=0;
	
	
	scanf("%d %d",&N,&M);
	for(i=0;i<M;i++)
		scanf("%d",&ary[i]);
	
	
	if(M<=N){
	   printf("%d\n",0);
	   return 0;
	}
	
	
	///////// BucketSort_1 //////////
	for(i=0;i<M;i++)
		bucket_1[ary[i]+100000]=1;
	for(i=0,j=0;i<M;j++)
		if(bucket_1[j]!=0){
			ary[i]=j-100000;
			i++;
		}
	
	
	for(i=0;i<M-1;i++)
	    margin[i]=ary[i+1]-ary[i];
	
		
	///////// BucketSort_2 //////////
	for(i=0;i<M-1;i++)
		bucket_2[margin[i]-1]+=1;	
	for(i=0,j=0;i<M-1;j++)
		if(bucket_2[j]!=0){
			for(k=0;k<bucket_2[j];k++){
				margin[i]=j+1;
				i++;
			}
		}
	
		
	
	for(i=M-2;M-N-1<i;i--)
	   notpass+=margin[i];
	
	
	printf("%d\n",ary[M-1]-ary[0]-notpass);
	
	
	return 0;
	
}
//  [c]
#include <stdio.h>
#include <stdlib.h>

long long cmp( const void *p, const void *q ) {
  return *(long long*)p - *(long long*)q;
}

int main(void){
  long long n,m,x[100005],L[100005];
  scanf("%lld%lld",&n,&m);
  for(int i=0;i<m;i++){
    scanf("%lld",&x[i]);
  }
  if(n>=m){
    printf("0\n");
    return 0;
  }
  qsort(x, m, sizeof(long long),cmp);
  if(n==1){
    printf("%lld\n",x[m-1]-x[0]);
    return 0;
  }
  for(int i=0;i<m-1;i++){
    L[i]=x[i+1]-x[i];
  }
  qsort(L, m, sizeof(long long),cmp);
 long long k=x[m-1]-x[0];
  for(int i=m-2;i>=m-n;i--){
    k-=L[i];
  }
  printf("%lld",k);

  return 0;
}
//  [c]
#include <stdio.h>
#include <stdlib.h>

long long cmp( const void *p, const void *q ) {
  return *(long long*)p - *(long long*)q;
}

int main(void){
  long long n,m,x[100005],L[100005];
  scanf("%lld%lld",&n,&m);
  for(int i=0;i<m;i++){
    scanf("%lld",&x[i]);
  }
  if(n>=m){
    printf("0\n");
    return 0;
  }
  qsort(x, m, sizeof(long long),cmp);
  if(n==1){
    printf("%lld\n",x[m-1]-x[0]);
    return 0;
  }
  for(int i=0;i<m;i++){
    L[i]=x[i+1]-x[i];
  }
  qsort(L, m, sizeof(long long),cmp);
 long long k=x[m-1]-x[0];
  for(int i=n-1;i>=1;i--){
    k-=L[i];
  }
  printf("%lld",k);

  return 0;
}
//  [c]
#include<stdio.h>

int main(){
  int N,M;
  scanf("%d%d",&N,&M);
  
  int s[M];
  for (int i=0;i<M;i++){
  scanf("%d",&s[i]);
  }
  for (int i=0;i<=M;i++){
    for (int j=i+1;j<=M;j++){
      if(s[i]>s[j]){
        int tmp =0;
        tmp = s[i];
        s[i] = s[j];
        s[j] = tmp;
      }
    }
  }
  
  
  int d[M-1];
  for (int i=0;i<M-1;i++){
    d[i]= s[i+1]-s[i];
  }
  
  for (int i=0;i<=M;i++){
    for (int j=i+1;j<=M;j++){
      if(d[i]>d[j]){
        int tmp = 0;
        tmp = d[i];
        d[i]=d[j];
        d[j]= tmp;
      }
    }
  }
  int ans=0;
  for (int i=0;i<M-N-1;i++){
    ans+=d[i];
  }
  
  printf("%d",ans);
  
  return 0;
}
//  [javascript]
function Main(input) {
  input = input.split("\n");
  input[0] = input[0].split(" ");
  input[1] = input[1].split(" ");
  var N=parseInt(input[0][0]);
  var M=parseInt(input[0][1]);
  var path=Math.max(M-N,0);
  if(path===0){
    console.log(0);
    return;
  }
  (function(){for(var i=0;i<M;i++){
    input[1][i]=parseInt(input[1][i]);
  }})();
  var Xs=input[1];
 
  var x_axis=[];
  var delta=[];
  (function(){for(var j=0;j<200001;j++){
    x_axis[j]=0;
    delta[j]=0;
  }})();
  (function(){for(var k=0;k<M;k++){
    x_axis[Xs[k]+100000]++;
  }})();
  (function(){
    var counter=0;
    var i=0;
    while(x_axis[i]===0){
      i++;
    }
    for(i=i+1;i<200001;i++){
      if(x_axis[i]===0){
        counter++;
        continue;
      }
      delta[counter+1]++;
      counter=0;
    }
  })();

  (function(){
    var counter=0;
    var deltax=0;
    for(var i=0;i<path;i++){
      while(delta[deltax]===0){
        deltax++;
      }
      delta[deltax]--;
      counter+=deltax;
      deltax=0;
    }
    console.log(counter);
  })();  
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
/**
 * 
 * @param {string} input 
 */
function main(input) {
  var inputList = input.split("\n");
  var nm = inputList[0].split(" ");
  var n = Number(nm[0]);
  var m = Number(nm[1]);
  var tmpList = inputList[1].split(" ");

  var xList = [];
  for(i=0; i<tmpList.length; i++){
    xList.push(Number(tmpList[i]));
  }

  // 座標ソート
  xList.sort(up);
  // 間の差
  var subList = [];
  for(i=0; i<xList.length-1; i++){
    var sub = Number(xList[i+1]) - Number(xList[i]);
    subList.push(sub);
  }

  // 差のソート昇順
  subList.sort(up);
  var sum = 0;
  for(i=0; i<subList.length-(n-1); i++){
    sum += subList[i];
  }
  
  console.log(sum);
}

function up(a, b){
  if(a<b){
    return -1;
  }else if(b<a){
    return 1;
  }else{
    return 0;
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
function main(input) {
    const args = input.split('\n');
    const Args = args[0].split(' ')
  	const N = parseInt(Args[0], 10)
    const M = parseInt(Args[1], 10)
    const L = args[1].split(' ').map(Number).sort(A)
  	var S = B(L,N)
    
    if(N>=M){
    	console.log(0)
    }else{
    	 console.log(S)
    }
    
}

var A = (a,b)=>{
  if( a > b ) return -1;
        if( a < b ) return 1;
        return 0;
}

var B = (l,n)=>{
    var a = []
    var s = 0
  	for(var i =0;i<l.length-1;i++){
    	a[i] = l[i] - l[i+1]
    }
    a.sort(A)
    for(var j = n-1;j<a.length;j++){
    	s += a[j]
    }
  	return s
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
const input = require("fs").readFileSync("/dev/stdin", "utf8")
;(input => {
    const rows = input.split('\n')
    const N = rows[0].split(' ').map(Number)[0]
    const M = rows[0].split(' ').map(Number)[1]
    const X = rows[1].split(' ').map(Number)

    X.sort((a, b) => a < b ? -1 : 1)

    const dp = []
    for (var i = 0; i < M - 1; i++) {
        dp[i] = X[i + 1] - X[i]
    }

    dp.sort((a, b) => a < b ? -1 : 1)
    dp.splice(dp.length - (N - 1), N - 1)

    console.log(dp.length ? dp.reduce((a, b) => a + b) : 0)

})(input)
//  [javascript]
const input = require("fs").readFileSync("/dev/stdin", "utf8")
;(input => {
    const rows = input.split('\n')
    const N = rows[0].split(' ').map(Number)[0]
    const M = rows[0].split(' ').map(Number)[1]
    const X = rows[1].split(' ').map(Number)

    X.sort((a, b) => a < b ? -1 : 1)

    const dp = []
    for (var i = 0; i < M - 1; i++) {
        dp[i] = X[i + 1] - X[i]
    }

    dp.sort((a, b) => a < b ? 1 : -1)
    dp.splice(0, N - 1)
    console.log(dp.length ? dp.reduce((a, b) => a + b) : 0)

})(input)
//  [javascript]
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

console.log(input);
//  [go]
package main

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

func main() {
	nm := nextIntArray()
	n, m := nm[0], nm[1]
	if n >= m {
		fmt.Println(0)
		return
	}
	x := nextIntArray()
	sort.Ints(x)
	for i := 1; i < m; i++ {
		x[i-1] -= x[i]
	}
	for i := 0; i < m; i++ {
		if x[i] < 0 {
			x[i] = -x[i]
		}
	}
	x = x[:len(x)-1]
	sort.Ints(x)
	cnt := 0
	for _, v := range x[:m-n] {
		cnt += v
	}
	fmt.Println(cnt)

}

func lcm(a, b int64) int64 {
	return (a / gcd(a, b)) * b
}

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

const size = 1000000

var reader = bufio.NewReaderSize(os.Stdin, size)

func nextLine() string {
	var line, buffer []byte
	isPrefix := true
	var err error
	for isPrefix {
		line, isPrefix, err = reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
	}
	return string(buffer)
}
func nextStringArray() []string {
	return strings.Split(nextLine(), " ")
}
func nextInt() int {
	n, _ := strconv.Atoi(nextLine())
	return n
}

func nextIntArray() []int {
	s := strings.Split(nextLine(), " ")
	n := len(s)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i], _ = strconv.Atoi(s[i])
	}
	return a
}

func min(i, j int) int {
	if i > j {
		return j
	}
	return i
}

func max(i, j int) int {
	if i < j {
		return j
	}
	return i
}
//  [go]
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func init() {
	scanner.Split(bufio.ScanWords)
}

func ScanInt() int {
	scanner.Scan()
	t := scanner.Text()
	n, _ := strconv.Atoi(t)
	return n
}

func main() {
	n, m := ScanInt(), ScanInt()
	if n >= m {
		fmt.Println(0)
		return
	}
	xs := make([]int, m)
	for i := 0; i < m; i++ {
		xs[i] = ScanInt()
	}
	sort.Ints(xs)
	ds := make([]int, m-1)
	for i := 0; i < m-1; i++ {
		ds[i] = xs[i+1] - xs[i]
	}
	ret := 0
	sort.Ints(ds)
	for i := 0; i < m-1-(n-1); i++ {
		ret += ds[i]
	}
	fmt.Println(ret)
}
//  [go]
package main

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

func main() {
	sc := NewScanner(os.Stdin)
	N := sc.NextInt()
	M := sc.NextInt()
	v := make([]int, M)
	for i := 0; i < M; i++ {
		v[i] = sc.NextInt()
	}
	sv := sort.IntSlice(v)
	sort.Sort(sv)
	d := make([]int, M-1)
	for i := 0; i < M-1; i++ {
		d[i] = sv[i+1] - sv[i]
	}
	sd := sort.IntSlice(d)
	sort.Sort(sd)
	ans := 0
	for i := 0; i < M-N; i++ {
		ans += sd[i]
	}
	fmt.Println(ans)
}

func lcm(x, y int) int {
	x, y = max(x, y), min(x, y)
	if y == 0 {
		return x
	}
	return lcm(y, x%y)
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

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

// scanner
type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner(r io.Reader) *Scanner {
	rdr := bufio.NewReaderSize(r, 1024)
	return &Scanner{r: rdr}
}

func (s *Scanner) ReadLine() {
	s.buf = make([]byte, 0)
	for {
		line, isp, err := s.r.ReadLine()
		if err != nil {
			os.Exit(1)
		}
		s.buf = append(s.buf, line...)
		if !isp {
			break
		}
	}
}

func (s *Scanner) NextInt() int {
	i, err := strconv.Atoi(s.Next())
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) NextFloat64() float64 {
	i, err := strconv.ParseFloat(s.Next(), 64)
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) Next() string {
	s.Pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	next := string(s.buf[start:s.p])
	s.p++
	return next
}

func (s *Scanner) Pre() {
	if s.p >= len(s.buf) {
		s.ReadLine()
		s.p = 0
	}
}
//  [go]
package main

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

var sc = bufio.NewScanner((os.Stdin))

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	l := nextLine()
	i, e := strconv.Atoi(l)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	N, M, X := nextInt(), nextInt(), []int{}
	for i := 0; i < M; i++ {
		X = append(X, nextInt())
	}

	fmt.Printf("%d\n", ABC117C(N, X))
}

// ABC117C ...
func ABC117C(N int, X []int) int {
	sort.Ints(X)

	if N == 1 {
		return X[len(X)-1] - X[0] + 1
	}

	dists := []int{}
	for i := 0; i < len(X)-1; i++ {
		dists = append(dists, X[i+1]-X[i])
	}
	sort.Ints(dists)

	res := 0
	for i := 0; i < len(dists)-N+1; i++ {
		res += dists[i]
	}

	return res
}
//  [go]
package main

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

var sc = bufio.NewScanner((os.Stdin))

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	l := nextLine()
	i, e := strconv.Atoi(l)
	if e != nil {
		panic(e)
	}
	return i
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func main() {
	sc.Split(bufio.ScanWords)
	N, M, X := nextInt(), nextInt(), []int{}
	for i := 0; i < M; i++ {
		X = append(X, nextInt())
	}

	fmt.Printf("%d\n", ABC117C(N, X))
}

// ABC117C ...
func ABC117C(N int, X []int) int {
	sort.Ints(X)

	if N == 1 {
		return X[len(X)-1] - X[0] + 1
	}

	div := [][]int{X}
	for d := 0; d < N-1; d++ {
		// select longest range
		var t []int
		max, maxIndex := -1, 0
		for i := 0; i < len(div); i++ {
			if max < len(div[i]) {
				max = len(div[i])
				maxIndex = i
			}
		}

		if max == 1 {
			break
		}

		t = div[maxIndex]

		l, r := t[0], t[len(t)-1]
		llist, rlist := []int{l}, []int{r}
		for i := 1; i < len(t)-1; i++ {
			if abs(t[i]-l) < abs(t[i]-r) {
				llist = append(llist, t[i])
				l = t[i]
			} else {
				rlist = append(rlist, t[i])
				sort.Ints(rlist)
				r = rlist[0]
			}
		}

		newdiv := [][]int{llist, rlist}
		for i := 0; i < len(div)-1; i++ {
			if i == maxIndex {
				continue
			}
			newdiv = append(newdiv, div[i])
		}
		div = newdiv
	}

	// count res
	res := 0
	for _, d := range div {
		res += d[len(d)-1] - d[0]
	}

	return res
}
//  [go]
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	m := iScan()
	x := iSScan(m)
	sort.Ints(x)
	y := make([]int, m-1)
	for i := 0; i < m-1; i++ {
		y[i] = x[i+1] - x[i]
	}
	sort.Sort(sort.Reverse(sort.IntSlice(y)))
	ans := sum(y)
	if len(y) > 0 {
		ans -= sum(y[:n-1])
	}
	fmt.Println(ans)
}
//  [ruby]
N, M = gets.split.map(&:to_i)
X = gets.split.map(&:to_i)
distance = Array.new(M-1, 0)
ans = 0

if N < M
  X.sort!
  (M-1).times do |i|
    distance[i] = X[i+1] - X[i]
  end
  distance.sort!
  ans = distance[0, M-N].inject(:+)
end

puts ans
//  [ruby]
N, M = gets.split.map(&:to_i)
X = gets.split.map(&:to_i).sort!

if N >= M
  puts 0
else
  d = []
  1.step(M-1) {|i| d << X[i] - X[i-1] }
  d.sort!.pop(N-1)
  puts d.inject(:+)
end
//  [ruby]
N, M = gets.split.map(&:to_i)
x = gets.split.map(&:to_i).sort

if N >= M
  puts 0
  exit
end

diff = []
0.upto(M-2) do |i|
  diff << x[i + 1] - x[i]
end

p diff.sort[0..-N].inject(:+)
//  [ruby]
n,m = gets.chomp.split(' ').map(&:to_i)
arr = gets.chomp.split(' ').map(&:to_i).sort.reverse
ans = 0
intervals = []
i = 1
while i < arr.size
  intervals << arr[i-1] - arr[i]
  i += 1
end
intervals.sort!
puts intervals[0..(m-n-1)].sum
//  [ruby]
N, M = gets.chomp.split().map(&:to_i)
X = gets.chomp.split().map(&:to_i).sort

X_pad = []
(M-1).times do |i|
  X_pad << X[i+1] - X[i]
end

X_pad.sort!
ans = 0
ans += X_pad[...-(N-1)].sum
puts ans
//  [ruby]
N, M = gets.chomp.split().map(&:to_i)
X = gets.chomp.split().map(&:to_i).sort

X_pad = X.map.with_index(1) { |x, i| X[i] - x if X[i] }.compact
l = X[-1] - X[0] 
exc_x = X_pad.empty? ? 0 : X_pad.sort[-(N-1)..].sum
puts l - exc_x
//  [rust]
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}
}

use input::*;

fn main() {
    let (n, m): (usize, usize);
    input!(n, m);
    let mut v = input_vector::<isize>();

    if n >= m {
        p(0);
        return;
    }

    let mut dist = vec![];

    v.sort();

    let mut sum = v.iter().last().unwrap() - v.iter().next().unwrap();
    for z in 0..m - 1 as usize {
        let buf = (v[z] - v[z + 1]).abs();
        dist.push(buf);
    }
    dist.sort();
    dist.reverse();
    for z in 0..n - 1 {
        sum -= dist[z];
    }
    p(sum);
}