program atcoder
    implicit none
    integer :: i,n,k,j
    integer,allocatable,dimension(:) :: a,dp
    read*,n,k
    allocate(a(0:n))
    allocate(dp(0:n+3))
    read(*,*)(a(i),i=1,n)
    dp = 1000000007
    dp(1) = 0
    do i = 1,n
        do j = 1,k
            if(i+j<=n) then
                dp(i+j) = min( dp(i+j) , dp(i)+abs(a(i)-a(i+j)) )
            endif
        end do
    end do
    write(*,'(I0)')dp(n)
    stop 
!---------------------------------------
contains

end program atcoder
