import sys

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

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

dp = [sys.maxsize] *n

dp[0] = 0

for i in range(n):

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

        if(j<n):

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

print((dp[n-1]))
import sys

def frog():

    for i in range(n):

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

            if(j<n):

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

    return dp[n-1]

if __name__ == "__main__":

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

        dp = [sys.maxsize] * n

        dp[0] = 0

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

        sys.stdout.write(str(frog()))
import sys

n, k = list(map(int, input().split()))
l = list(map(int, input().split()))
dp = [sys.maxsize] * n
dp[0] = 0
for i in range(n):
    for j in range(i + 1, i + k + 1):
        if j < n:
            dp[j] = min(dp[j], dp[i] + abs(l[i] - l[j]))
print((dp[n - 1]))

import sys


def frog():
    for i in range(n):
        for j in range(i + 1, i + k + 1):
            if j < n:
                dp[j] = min(dp[j], dp[i] + abs(l[i] - l[j]))
    return dp[n - 1]


if __name__ == "__main__":
    n, k = list(map(int, input().split()))
    dp = [sys.maxsize] * n
    dp[0] = 0
    l = list(map(int, input().split()))
    sys.stdout.write(str(frog()))

-n, k = list(map(int, input().split())) -l = list(map(int, input().split())) -dp = [sys.maxsize] * n -dp[0] = 0 -for i in range(n): -    for j in range(i + 1, i + k + 1): -        if j < n: -            dp[j] = min(dp[j], dp[i] + abs(l[i] - l[j])) -print((dp[n - 1])) + +def frog(): +    for i in range(n): +        for j in range(i + 1, i + k + 1): +            if j < n: +                dp[j] = min(dp[j], dp[i] + abs(l[i] - l[j])) +    return dp[n - 1] + + +if __name__ == "__main__": +    n, k = list(map(int, input().split())) +    dp = [sys.maxsize] * n +    dp[0] = 0 +    l = list(map(int, input().split())) +    sys.stdout.write(str(frog()))