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

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



INF = float('inf')

dp = [INF] * N

dp[0] = 0

for i in range(1,N):

    for j in range(K):

        if i-j-1 < 0: break

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

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

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

dp = [10**18]*N

dp[0] = 0

for i in range(1,N):

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

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

print((dp[-1]))
N, K = list(map(int, input().split()))
H = list(map(int, input().split()))
INF = float("inf")
dp = [INF] * N
dp[0] = 0
for i in range(1, N):
    for j in range(K):
        if i - j - 1 < 0:
            break
        dp[i] = min(dp[i], dp[i - j - 1] + abs(H[i] - H[i - j - 1]))
print((dp[-1]))

N, K = list(map(int, input().split()))
H = list(map(int, input().split()))
dp = [10**18] * N
dp[0] = 0
for i in range(1, N):
    for j in range(max(0, i - K), i):
        dp[i] = min(dp[i], dp[j] + abs(H[i] - H[j]))
print((dp[-1]))

-INF = float("inf") -dp = [INF] * N +dp = [10**18] * N -    for j in range(K): -        if i - j - 1 < 0: -            break -        dp[i] = min(dp[i], dp[i - j - 1] + abs(H[i] - H[i - j - 1])) +    for j in range(max(0, i - K), i): +        dp[i] = min(dp[i], dp[j] + abs(H[i] - H[j]))