import sys

sys.setrecursionlimit(100000) 

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

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

A = [0]*(n)

if k >= n:

    k = n

for i in range(1,k):

    A[i] = abs(l[i]-l[0])

for i in range(k,n):

    tmp = float('Inf')

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

        dis = A[i-j] + abs(l[i]-l[i-j])

        tmp = min(tmp,dis)

    A[i] = tmp

print((A[n-1]))

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

if n <= k:

    k = n

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

dp = [float('inf') for _ in range(n+1)]

for i in range(k):

    dp[i] = abs(H[i] - H[0])

for i in range(k,n):

    for j in range(k+1):

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

print((dp[-2]))
import sys

sys.setrecursionlimit(100000)
n, k = list(map(int, input().split()))
l = list(map(int, input().split()))
A = [0] * (n)
if k >= n:
    k = n
for i in range(1, k):
    A[i] = abs(l[i] - l[0])
for i in range(k, n):
    tmp = float("Inf")
    for j in range(1, k + 1):
        dis = A[i - j] + abs(l[i] - l[i - j])
        tmp = min(tmp, dis)
    A[i] = tmp
print((A[n - 1]))

n, k = list(map(int, input().split()))
if n <= k:
    k = n
H = list(map(int, input().split()))
dp = [float("inf") for _ in range(n + 1)]
for i in range(k):
    dp[i] = abs(H[i] - H[0])
for i in range(k, n):
    for j in range(k + 1):
        dp[i] = min(dp[i], dp[i - j] + abs(H[i] - H[i - j]))
print((dp[-2]))

-import sys - -sys.setrecursionlimit(100000) -l = list(map(int, input().split())) -A = [0] * (n) -if k >= n: +if n <= k: -for i in range(1, k): -    A[i] = abs(l[i] - l[0]) +H = list(map(int, input().split())) +dp = [float("inf") for _ in range(n + 1)] +for i in range(k): +    dp[i] = abs(H[i] - H[0]) -    tmp = float("Inf") -    for j in range(1, k + 1): -        dis = A[i - j] + abs(l[i] - l[i - j]) -        tmp = min(tmp, dis) -    A[i] = tmp -print((A[n - 1])) +    for j in range(k + 1): +        dp[i] = min(dp[i], dp[i - j] + abs(H[i] - H[i - j])) +print((dp[-2]))