program Frog_2
    implicit none
    integer(4):: n,k
    integer(4):: i,j
    integer(4),parameter:: inf=200000*10000+1
    integer(4), allocatable:: h(:), dp(:)


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

    read*, h(:)
    dp(:) = inf
    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)-h(i+j)))
        end do
    end do

    print*, dp(n)

end program Frog_2