n, k = [int(i) for i in input().split()]

h = [int(i) for i in input().split()]

 

def frog(n, k, h):

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

    d[0] = 0

 

    for i in range(1, n):

        d[i] = min(

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

        )

    return d[n - 1]

 

 

print((frog(n, k, h)))
n, k = [int(i) for i in input().split()]

h = [int(i) for i in input().split()]

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

dp[0] = 0



for i in range(1, n):

    for j in range(max(i - k, 0), i):

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



print((dp[n - 1]))

n, k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]


def frog(n, k, h):
    d = [float("inf")] * n
    d[0] = 0
    for i in range(1, n):
        d[i] = min(d[j] + abs(h[i] - h[j]) for j in range(max(i - k, 0), i))
    return d[n - 1]


print((frog(n, k, h)))

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

- - -def frog(n, k, h): -    d = [float("inf")] * n -    d[0] = 0 -    for i in range(1, n): -        d[i] = min(d[j] + abs(h[i] - h[j]) for j in range(max(i - k, 0), i)) -    return d[n - 1] - - -print((frog(n, k, h))) +dp = [float("inf")] * n +dp[0] = 0 +for i in range(1, n): +    for j in range(max(i - k, 0), i): +        dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j])) +print((dp[n - 1]))