program main
  implicit none

  integer(16),allocatable :: h(:), dp(:)
  integer(16) :: n, k, inf, i, j

  read(*,*) n, k
  allocate(h(n))
  allocate(dp(n))
  read(*,*) h

  inf = 100000000000_16
  do i = 1, n
     dp(i) = inf
  end do

  dp(1) = 0

  do j = 2, n
     do i = 1, k
        if(j > i) then
           dp(j) = min(dp(j), dp(j-i)+abs(h(j) - h(j-i)))
        end if
     end do
  end do

  write(*,*) dp(n)

end program main


     
