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

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



dp=["INF" for _ in range(n)]

dp[0]=0

#print(r)



for i in range(n):

  for j in range(min(k,n-i-1)):

    if dp[i+j+1]=="INF":

      dp[i+j+1]=dp[i]+abs(a[i+j+1]-a[i])

    else:

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

      #print(i,i+j,">>",r)

  

print((dp[-1]))

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

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



dp=[100000000000000000 for _ in range(n)]

dp[0]=0

#print(r)



for i in range(n):

  for j in range(min(k,n-i-1)):

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

      #print(i,i+j,">>",r)

  

print((dp[-1]))

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
dp = ["INF" for _ in range(n)]
dp[0] = 0
# print(r)
for i in range(n):
    for j in range(min(k, n - i - 1)):
        if dp[i + j + 1] == "INF":
            dp[i + j + 1] = dp[i] + abs(a[i + j + 1] - a[i])
        else:
            dp[i + j + 1] = min(dp[i + j + 1], dp[i] + abs(a[i + j + 1] - a[i]))
            # print(i,i+j,">>",r)
print((dp[-1]))

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
dp = [100000000000000000 for _ in range(n)]
dp[0] = 0
# print(r)
for i in range(n):
    for j in range(min(k, n - i - 1)):
        dp[i + j + 1] = min(dp[i + j + 1], dp[i] + abs(a[i + j + 1] - a[i]))
        # print(i,i+j,">>",r)
print((dp[-1]))

-dp = ["INF" for _ in range(n)] +dp = [100000000000000000 for _ in range(n)] -        if dp[i + j + 1] == "INF": -            dp[i + j + 1] = dp[i] + abs(a[i + j + 1] - a[i]) -        else: -            dp[i + j + 1] = min(dp[i + j + 1], dp[i] + abs(a[i + j + 1] - a[i])) -            # print(i,i+j,">>",r) +        dp[i + j + 1] = min(dp[i + j + 1], dp[i] + abs(a[i + j + 1] - a[i])) +        # print(i,i+j,">>",r)