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

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

dp = [float('INF') for i in range(N)]

dp[0] = 0



def change_min(a, b):

  if a > b: return b

  else: return a



for i in range(N):

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

    if i + j > N - 1: continue

    dp[i + j] = change_min(dp[i] + abs(h_list[i] - h_list[i + j]), dp[i + j])



print((dp[N - 1]))
N, K = list(map(int, input().split()))

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

dp = [float('INF') for i in range(N)]

dp[0] = 0

 

def update_dp(now, next):

  global h_list

  global dp

  global N

  if next > N - 1: return

  if dp[next] > dp[now] + abs(h_list[next] - h_list[now]):

    dp[next] = dp[now] + abs(h_list[next] - h_list[now])

  return

 

for i in range(N):

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

    update_dp(i, i + j)

 

print((dp[N - 1]))
N, K = list(map(int, input().split()))
h_list = list(map(int, input().split()))
dp = [float("INF") for i in range(N)]
dp[0] = 0


def change_min(a, b):
    if a > b:
        return b
    else:
        return a


for i in range(N):
    for j in range(1, K + 1):
        if i + j > N - 1:
            continue
        dp[i + j] = change_min(dp[i] + abs(h_list[i] - h_list[i + j]), dp[i + j])
print((dp[N - 1]))

N, K = list(map(int, input().split()))
h_list = list(map(int, input().split()))
dp = [float("INF") for i in range(N)]
dp[0] = 0


def update_dp(now, next):
    global h_list
    global dp
    global N
    if next > N - 1:
        return
    if dp[next] > dp[now] + abs(h_list[next] - h_list[now]):
        dp[next] = dp[now] + abs(h_list[next] - h_list[now])
    return


for i in range(N):
    for j in range(1, K + 1):
        update_dp(i, i + j)
print((dp[N - 1]))

-def change_min(a, b): -    if a > b: -        return b -    else: -        return a +def update_dp(now, next): +    global h_list +    global dp +    global N +    if next > N - 1: +        return +    if dp[next] > dp[now] + abs(h_list[next] - h_list[now]): +        dp[next] = dp[now] + abs(h_list[next] - h_list[now]) +    return -        if i + j > N - 1: -            continue -        dp[i + j] = change_min(dp[i] + abs(h_list[i] - h_list[i + j]), dp[i + j]) +        update_dp(i, i + j)