N,K = list(map(int,input().split()))

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

 

dp = [100000000000]*N

 

dp[0] = 0

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

 

for i in range(2,N):

  for num in range(K):

    if num+1<=i:

      A = dp[i-num-1]+abs(h[i]-h[i-num-1])

      if dp[i] >= A:

        dp[i] = A

 

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

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

INF = 10**18



dp = [INF] * (n)

dp[0] = 0



for i in range(n):

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

        if i+j < n:

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

        else:

            break

print((dp[-1]))
N, K = list(map(int, input().split()))
h = list(map(int, input().split()))
dp = [100000000000] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2, N):
    for num in range(K):
        if num + 1 <= i:
            A = dp[i - num - 1] + abs(h[i] - h[i - num - 1])
            if dp[i] >= A:
                dp[i] = A
print((dp[N - 1]))

n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
INF = 10**18
dp = [INF] * (n)
dp[0] = 0
for i in range(n):
    for j in range(1, k + 1):
        if i + j < n:
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
        else:
            break
print((dp[-1]))

-N, K = list(map(int, input().split())) +n, k = list(map(int, input().split())) -dp = [100000000000] * N +INF = 10**18 +dp = [INF] * (n) -dp[1] = abs(h[1] - h[0]) -for i in range(2, N): -    for num in range(K): -        if num + 1 <= i: -            A = dp[i - num - 1] + abs(h[i] - h[i - num - 1]) -            if dp[i] >= A: -                dp[i] = A -print((dp[N - 1])) +for i in range(n): +    for j in range(1, k + 1): +        if i + j < n: +            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i])) +        else: +            break +print((dp[-1]))