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

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



dp=[0]*n

def calc(n,k,h,dp):

    for i in range(1,n):

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



calc(n,k,h,dp)

print((dp[-1]))

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

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

h+=[0]*k

inf=10**9

dp=[inf]*(n+k)

dp[0]=0

for i in range(n):

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

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

print((dp[n-1]))

n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
dp = [0] * n


def calc(n, k, h, dp):
    for i in range(1, n):
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(max(i - k, 0), i)])


calc(n, k, h, dp)
print((dp[-1]))

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

-dp = [0] * n - - -def calc(n, k, h, dp): -    for i in range(1, n): -        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(max(i - k, 0), i)]) - - -calc(n, k, h, dp) -print((dp[-1])) +h += [0] * k +inf = 10**9 +dp = [inf] * (n + k) +dp[0] = 0 +for i in range(n): +    for j in range(1, k + 1): +        dp[i + j] = min(dp[i] + abs(h[i] - h[i + j]), dp[i + j]) +print((dp[n - 1]))