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

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



INF = 10**5



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

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

# DP = [None] * (N+1)

DP[0] = 0



for i in range(1, N):

    a = []

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

        if 0 <= i-j < N:

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

            a.append(v)

    DP[i] = min(a)





# print(DP)

print((DP[N-1]))
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**5
DP = [INF] * ((10**5) + 10)
# DP = [None] * ((10**5)+10)
# DP = [None] * (N+1)
DP[0] = 0
for i in range(1, N):
    a = []
    for j in range(1, K + 1):
        if 0 <= i - j < N:
            v = DP[i - j] + abs(H[i - j] - H[i])
            a.append(v)
    DP[i] = min(a)
# print(DP)
print((DP[N - 1]))

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)

-INF = 10**5 -DP = [INF] * ((10**5) + 10) -# DP = [None] * ((10**5)+10) -# DP = [None] * (N+1) +INF = 10**6 +# DP = [INF] * N +# DP = [INF] * ((10**5)+10) +DP = [float("inf")] * N +# 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])) -    a = [] -        if 0 <= i - j < N: -            v = DP[i - j] + abs(H[i - j] - H[i]) -            a.append(v) -    DP[i] = min(a) +        # 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 - 1]))