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

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

inf = 10 ** 4 + 1

dp = [inf] * N

dp[0] = 0

for i in range(1,N):

    H = h[i]

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

print((dp[-1]))

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

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



if N-1<=K:

    print((abs(H[N-1]-H[0])))

    exit()



inf=10**4+1

dp=[inf]*N

dp[0]=0



for i,h in enumerate(H):

    if i == 0:continue

    m=inf

    M=max(0,i-K)

    dp[i]=min([dpt+abs(h-ht) for ht,dpt in zip(H[M:i],dp[M:i])])

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

N, K = list(map(int, input().split()))
H = list(map(int, input().split()))
if N - 1 <= K:
    print((abs(H[N - 1] - H[0])))
    exit()
inf = 10**4 + 1
dp = [inf] * N
dp[0] = 0
for i, h in enumerate(H):
    if i == 0:
        continue
    m = inf
    M = max(0, i - K)
    dp[i] = min([dpt + abs(h - ht) for ht, dpt in zip(H[M:i], dp[M:i])])
print((dp[N - 1]))

-h = list(map(int, input().split())) +H = list(map(int, input().split())) +if N - 1 <= K: +    print((abs(H[N - 1] - H[0]))) +    exit() -for i in range(1, N): -    H = h[i] -    dp[i] = min([dp[j] + abs(h[j] - H) for j in range(max(0, i - K), i)]) -print((dp[-1])) +for i, h in enumerate(H): +    if i == 0: +        continue +    m = inf +    M = max(0, i - K) +    dp[i] = min([dpt + abs(h - ht) for ht, dpt in zip(H[M:i], dp[M:i])]) +print((dp[N - 1]))