from collections import Counter

from collections import deque

import math

import bisect

import sys

def input(): return sys.stdin.readline().strip()

def mp(): return list(map(int,input().split()))

def lmp(): return list(map(int,input().split()))





n,k=mp()

h=lmp()

h.insert(0,0)

dp=[float("inf")]*(n+1)

dp[1]=0

for i in range(1,n+1):

    for j in range(1,k+1):

        if i+j<=n:

            dp[i+j]=min(dp[i+j],abs(h[i+j]-h[i])+dp[i])

print((dp[n]))

n,k = list(map(int,input().split()))

height = list(map(int,input().split()))

cost_list = []

for m in range(1,n+1):

  if m <= k:

    cost_list.append(abs(height[m-1]-height[0]))

  else:

    Min = cost_list[-1] + abs(height[m-2]-height[m-1])

    if k > 1:

      for x in range(2,k+1):

        money2 = cost_list[-x] + abs(height[m-x-1]-height[m-1])

        if money2 < Min:

          Min = money2 

    cost_list.append(Min)

print((cost_list[-1]))
from collections import Counter
from collections import deque
import math
import bisect
import sys


def input():
    return sys.stdin.readline().strip()


def mp():
    return list(map(int, input().split()))


def lmp():
    return list(map(int, input().split()))


n, k = mp()
h = lmp()
h.insert(0, 0)
dp = [float("inf")] * (n + 1)
dp[1] = 0
for i in range(1, n + 1):
    for j in range(1, k + 1):
        if i + j <= n:
            dp[i + j] = min(dp[i + j], abs(h[i + j] - h[i]) + dp[i])
print((dp[n]))

n, k = list(map(int, input().split()))
height = list(map(int, input().split()))
cost_list = []
for m in range(1, n + 1):
    if m <= k:
        cost_list.append(abs(height[m - 1] - height[0]))
    else:
        Min = cost_list[-1] + abs(height[m - 2] - height[m - 1])
        if k > 1:
            for x in range(2, k + 1):
                money2 = cost_list[-x] + abs(height[m - x - 1] - height[m - 1])
                if money2 < Min:
                    Min = money2
        cost_list.append(Min)
print((cost_list[-1]))

-from collections import Counter -from collections import deque -import math -import bisect -import sys - - -def input(): -    return sys.stdin.readline().strip() - - -def mp(): -    return list(map(int, input().split())) - - -def lmp(): -    return list(map(int, input().split())) - - -n, k = mp() -h = lmp() -h.insert(0, 0) -dp = [float("inf")] * (n + 1) -dp[1] = 0 -for i in range(1, n + 1): -    for j in range(1, k + 1): -        if i + j <= n: -            dp[i + j] = min(dp[i + j], abs(h[i + j] - h[i]) + dp[i]) -print((dp[n])) +n, k = list(map(int, input().split())) +height = list(map(int, input().split())) +cost_list = [] +for m in range(1, n + 1): +    if m <= k: +        cost_list.append(abs(height[m - 1] - height[0])) +    else: +        Min = cost_list[-1] + abs(height[m - 2] - height[m - 1]) +        if k > 1: +            for x in range(2, k + 1): +                money2 = cost_list[-x] + abs(height[m - x - 1] - height[m - 1]) +                if money2 < Min: +                    Min = money2 +        cost_list.append(Min) +print((cost_list[-1]))