PROGRAM ATCODER

implicit none
integer :: n, m, i, j, a, ans
integer,allocatable :: x(:), dx(:),dx1(:),bar(:)

read(*,*) n, m
allocate(x(m))
allocate(dx(m-1))
allocate(dx1(m-1))
allocate(bar(n-1))
read(*,*) (x(i), i=1,m)

if(n >= m) then
	ans = 0
	write(*,'(i0)') ans
    stop
end if

if(n == 1) then
	ans = x(m) - x(1)
    write(*,'(i0)') ans
    stop
end if

call hsort(m,x) !昇順に並び替え

do i =1, m-1
	dx(i) = x(i+1) - x(i)
    dx1(i) = dx(i)
end do

do i = 1, n-1
	a = maxloc(dx1,1)
	bar(i) = a
    dx1(a) = 0
end do

call hsort(n-1,bar)

ans = x(bar(1))-x(1) + x(m) - x(bar(n-1)+1)
do i = 1, n-2
		ans = ans + x(bar(i+1)) - x(bar(i)+1)
end do

write(*,'(i0)') ans

END PROGRAM ATCODER


subroutine hsort(n, x)
  implicit none
  integer, intent(IN) :: n
  integer, intent(INOUT) :: x(n)
  ! local
  integer k
  real(8) :: tmp
  ! external subroutine
  external mkheap

  do k = n/2, 1, -1
     tmp = x(k)
     call mkheap(n, x, k, n, tmp)
  enddo

  do k = n, 2, -1
     tmp = x(k)
     x(k) = x(1)
     call mkheap(n, x, 1, k-1, tmp)
  end do

  return
end subroutine hsort


subroutine mkheap(n, x, root, leaf, val)
  implicit none
  integer, intent(IN)    :: n, root, leaf
  integer, intent(INOUT) :: x(1:n)
  real(8), intent(IN)    :: val
  ! local
  integer :: i, j

  i = root
  j = i * 2

  do
     if (j > leaf) exit

     if (j < leaf) then
        if (x(j) < x(j+1)) j = j + 1
     end if

     if (x(j) > val) then
        x(i) = x(j)
        i = j
        j = i * 2
     else
        j = leaf + 1
     endif
  end do

  x(i) = val

  return
end subroutine mkheap
