!ref
!https://qiita.com/drken/items/dc53c683d6de8aeacf5a
      PROGRAM Frog2
      IMPLICIT NONE
      integer(16) :: n,k
      integer(16),allocatable :: h(:),dp(:)
      integer(16) :: i,j
      
      read*, n,k
      allocate( h(1:n) )
      read*, h(:)
      
      
      allocate( dp(1:n) )
      dp(:) = 10**5
      dp(1) = 0
      
      
      do i = 1,n
        do j = 1,k
          if( i+j>n ) cycle
          dp(i+j) = min( dp(i+j), dp(i)+abs( h(i+j)-h(i) ) )
        end do
      end do
      
      print*,dp(n)
      
      END PROGRAM