integer N,K
integer,allocatable,dimension(:)::H
integer DP(10**5)
read*,N,K
allocate(H(N))
read*,H

DP=huge(DP)/2
DP(1)=0
DP(2)=abs(H(2)-H(1))
if(N==2)then
  print"(i0)",DP(N)
  STOP
endif
do i=3,N
  do j=1,min(K,i-1)
    DP(i)=min(DP(i-j)+abs( H(i)-H(i-j) ),DP(i))
  end do
end do
print"(i0)",DP(N)
end
