integer n,m,a,ans
integer,allocatable,dimension(:)::x,dx(:)

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

if(n >= m)then
  print"(i0)",0
  stop
end if

call heapsort(m,x)

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

call heapsort(m-1,dx)

ans = sum(dx)
if (n > 1)ans = ans - sum(dx(m-n+1:m-1))
print"(i0)",ans

contains

subroutine heapsort(n,array)
  implicit none
!ここの入力は状況に応じて変更すること
  integer,intent(in) :: n
  integer,intent(inout) :: array(1:n)
  integer::i,k,j,l
  integer:: t

  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j<=k)
        if(j < k)then
           if(array(j) < array(j+1))j=j+1
        endif
        if (t < array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo
  return
end subroutine heapsort
end