program bbb

integer(8) :: n, k, i, j
integer(8),allocatable,dimension(:) :: h, dp

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

dp=10**9
dp(1)=0
do i=2, n
 do j=1, k
 dp(i)=min(dp(i-j)+abs(h(i-j)-h(i)),dp(i))
 end do
end do

write(*,'(i0)') dp(n)

end program