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

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



dp = [float('inf')] * n



dp[0] = 0

for i in range(1, n):

  dp[i] = min(dp[j]+abs(h[i]-h[j]) for j in range(max(0, i-k), i))



    

print((dp[n-1]))
n,k=list(map(int,input().split()))

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

dp=[float('inf')]*n

dp[0]=0

dp[1]=abs(h[1]-h[0])

for i in range(2,n):

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

    if i-j>=0:

      res=abs(h[i]-h[i-j])

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

    else:

      break

print((dp[n-1]))

  
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
dp = [float("inf")] * n
dp[0] = 0
for i in range(1, n):
    dp[i] = min(dp[j] + abs(h[i] - h[j]) for j in range(max(0, i - k), i))
print((dp[n - 1]))

n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
dp = [float("inf")] * n
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2, n):
    for j in range(1, k + 1):
        if i - j >= 0:
            res = abs(h[i] - h[i - j])
            dp[i] = min(dp[i], dp[i - j] + res)
        else:
            break
print((dp[n - 1]))

-for i in range(1, n): -    dp[i] = min(dp[j] + abs(h[i] - h[j]) for j in range(max(0, i - k), i)) +dp[1] = abs(h[1] - h[0]) +for i in range(2, n): +    for j in range(1, k + 1): +        if i - j >= 0: +            res = abs(h[i] - h[i - j]) +            dp[i] = min(dp[i], dp[i - j] + res) +        else: +            break