import numpy as np



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

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

A = np.array(A)

dp = np.zeros(N, dtype=int)

dp[0] = 0

if N > K:

    for i in range(1,N):

        if i <= K:

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

        else:

            j = max(i - K, 0)

            dp[i] = np.min(np.abs(A[i] - A[j:i]) + dp[j:i])

    print((dp[N-1]))

else:

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


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

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

dp = [0 for i in range(N)]

dp[0] = 0

if N > K:

    for i in range(1,N):

        if i <= K:

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

        else:

            L = []

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

                L.append(abs(A[i]-A[i-j]) + dp[i-j])

            dp[i] = min(L)

    print((dp[N-1]))

else:

    print((abs(A[N-1]-A[0])))
import numpy as np

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A = np.array(A)
dp = np.zeros(N, dtype=int)
dp[0] = 0
if N > K:
    for i in range(1, N):
        if i <= K:
            dp[i] = abs(A[i] - A[0])
        else:
            j = max(i - K, 0)
            dp[i] = np.min(np.abs(A[i] - A[j:i]) + dp[j:i])
    print((dp[N - 1]))
else:
    print((abs(A[N - 1] - A[0])))

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
dp = [0 for i in range(N)]
dp[0] = 0
if N > K:
    for i in range(1, N):
        if i <= K:
            dp[i] = abs(A[i] - A[0])
        else:
            L = []
            for j in range(1, K + 1):
                L.append(abs(A[i] - A[i - j]) + dp[i - j])
            dp[i] = min(L)
    print((dp[N - 1]))
else:
    print((abs(A[N - 1] - A[0])))

-import numpy as np - -A = np.array(A) -dp = np.zeros(N, dtype=int) +dp = [0 for i in range(N)] -            j = max(i - K, 0) -            dp[i] = np.min(np.abs(A[i] - A[j:i]) + dp[j:i]) +            L = [] +            for j in range(1, K + 1): +                L.append(abs(A[i] - A[i - j]) + dp[i - j]) +            dp[i] = min(L)