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

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



INF = 10**6



# DP = [INF] * N

# DP = [INF] * ((10**5)+10)

DP = [float('inf')] * N

DP[0] = 0



# for i in range(1, N):

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

#         if 0 <= i - j < N:

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



for i in range(1, N):

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

        # if 0 <= i - j < N:

        if i - j < 0:

            break

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



print((DP[N-1]))

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

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



INF = 10**4 * 10**5 + 1



DP = [INF] * N

# DP = [INF] * ((10**5)+10)

# DP = [float('inf')] * N

DP[0] = 0



# for i in range(1, N):

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

#         if 0 <= i - j < N:

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



for i in range(1, N):

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

        # if 0 <= i - j < N:

        if i - j < 0:

            break

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



print((DP[N-1]))

# print(DP)
N, K = list(map(int, input().split()))
H = list(map(int, input().split()))
INF = 10**6
# DP = [INF] * N
# DP = [INF] * ((10**5)+10)
DP = [float("inf")] * N
DP[0] = 0
# for i in range(1, N):
#     for j in range(1, K+1):
#         if 0 <= i - j < N:
#             DP[i] = min(DP[i], DP[i-j] + abs(H[i-j] - H[i]))
for i in range(1, N):
    for j in range(1, K + 1):
        # if 0 <= i - j < N:
        if i - j < 0:
            break
        DP[i] = min(DP[i], DP[i - j] + abs(H[i] - H[i - j]))
print((DP[N - 1]))
# print(DP)

N, K = list(map(int, input().split()))
H = list(map(int, input().split()))
INF = 10**4 * 10**5 + 1
DP = [INF] * N
# DP = [INF] * ((10**5)+10)
# DP = [float('inf')] * N
DP[0] = 0
# for i in range(1, N):
#     for j in range(1, K+1):
#         if 0 <= i - j < N:
#             DP[i] = min(DP[i], DP[i-j] + abs(H[i-j] - H[i]))
for i in range(1, N):
    for j in range(1, K + 1):
        # if 0 <= i - j < N:
        if i - j < 0:
            break
        DP[i] = min(DP[i], DP[i - j] + abs(H[i] - H[i - j]))
print((DP[N - 1]))
# print(DP)

-INF = 10**6 -# DP = [INF] * N +INF = 10**4 * 10**5 + 1 +DP = [INF] * N -DP = [float("inf")] * N +# DP = [float('inf')] * N