program main
implicit none
integer ::n , m
integer , allocatable :: x(:), y(:)
integer :: i
integer :: a

read(*,*) n,m 
allocate(x(m))
allocate(y(m-1))
read(*,*) x
call bubble(m,x)
do i = 1, m-1
   y(i) = x(i+1)-x(i)
end do
call bubble(m-1,y)

a = 0
if( n.ge.m ) then
   a = 0
else
   do i = 1, m-n
      a = a + y(i)
   end do
end if

write(*,'(i0)') a
deallocate(x)
deallocate(y)

stop
contains
  subroutine bubble(n,array)
    implicit none
    integer , intent(in) :: n
    integer , intent(inout) :: array(n)
    integer :: i, j
    integer :: t

    do i = 1, n-1
       do j = i+1 , n
          if(array(i).gt.array(j))then
             t = array(i)
             array(i) = array(j)
             array(j) = t
          end if
       end do
    end do
  end subroutine bubble



end program main
