output_description: Find the minimum number of moves required to achieve the objective.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M
      X_1 X_2 ... X_M
attempt: import sys
  
  s2nn = lambda s: [int(c) for c in s.split(" ")]
  ss2nn = lambda ss: [int(s) for s in list(ss)]
  ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
  i2s = lambda: sys.stdin.readline().rstrip()
  i2n = lambda: int(i2s())
  i2nn = lambda: s2nn(i2s())
  ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]
  
  
  # n: コマ
  # x: 目的地 len(x)=M
  def main(N, M, Xm):
      # コマ数N >= 目的地数M: クリア
      if N >= M:
          print(0)
          return
      # 目的地は個体区別しないので、簡単のためソート
      Xm.sort()
      # コマ数N == 1: 1コマで端から端まで移動
      if N == 1:
          d = Xm[M - 1] - Xm[0]
          print(d)
          return
      # 2 <= コマ数N < 目的地数M: どうする？
      # 発想を変えて、目的地間の距離に注目
      Dm = [Xm[i] - Xm[i - 1] for i in range(1, M)]
      # 区間は、間隔が短い順に並ぶとする
      Dm.sort()
      # 全てのコマの移動方向は右とする
      # コマ1は一番左の目的地からスタート
      # コマ2～Nは右端の目的地から埋めていく
      # 1             5     4      3       2      コマ
      # x-x--x---x----x-----x------x-------x      目的地（区間が短い順）
      # あとは、コマ1が、コマNの隣まで進めばよい、その距離が答えとなる
      d = 0
      for i in range(M - N):
          d += Dm[i]
      print(d)
  
  
  N, M = i2nn()
  Xm = i2nn()
  main(N, M, Xm)
  
  """
  C - Streamline
  https://atcoder.jp/contests/abc117/tasks/abc117_c
  
  2 5
  10 12 1 2 14
      5
  
  3 7
  -10 -3 0 9 -100 2 17
      19
  
  100 1
  -100000
      0
  """
  
problem_description: Statement
  
  We will play a one-player game using a number line and N pieces.
  
  First, we place each of these pieces at some integer coordinate.
  
  Here, multiple pieces can be placed at the same coordinate.
  
  Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with
  these pieces, by repeating the following move:
  
  **Move** : Choose a piece and let x be its coordinate. Put that piece at
  coordinate x+1 or x-1.
  
  Note that the coordinates where we initially place the pieces are already
  regarded as visited.
  
  Find the minimum number of moves required to achieve the objective.
samples: [{"input": "2 5\n    10 12 1 2 14", "output": "5\n    \n\nThe objective can be achieved in five moves as follows, and this is the\nminimum number of moves required.\n\n  * Initially, put the two pieces at coordinates 1 and 10.\n  * Move the piece at coordinate 1 to 2.\n  * Move the piece at coordinate 10 to 11.\n  * Move the piece at coordinate 11 to 12.\n  * Move the piece at coordinate 12 to 13.\n  * Move the piece at coordinate 13 to 14.\n\n* * *"}, {"input": "3 7\n    -10 -3 0 9 -100 2 17", "output": "19\n    \n\n* * *"}, {"input": "100 1\n    -100000", "output": "0"}]