#b

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

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



N=100010

INF=float('INF')

dp=[INF]*N

dp[0]=0



for i in range(1,n):

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

        if i-j>=0:

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



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

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

dp=[0]*n 



for i in range(1,n):

    dp[i]=10**10

    for k in range(1,min(K,i)+1):

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

print((dp[n-1]))
# b
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
N = 100010
INF = float("INF")
dp = [INF] * N
dp[0] = 0
for i in range(1, n):
    for j in range(1, k + 1):
        if i - j >= 0:
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))
print((dp[n - 1]))

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

-# b -n, k = list(map(int, input().split())) +n, K = list(map(int, input().split())) -N = 100010 -INF = float("INF") -dp = [INF] * N -dp[0] = 0 +dp = [0] * n -    for j in range(1, k + 1): -        if i - j >= 0: -            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j])) +    dp[i] = 10**10 +    for k in range(1, min(K, i) + 1): +        dp[i] = min(dp[i], dp[i - k] + abs(h[i] - h[i - k]))