output_description: Print the minimum possible total cost incurred.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N K
      h_1 h_2 \ldots h_N
attempt: INF = float("inf")
  
  import sys
  
  sys.setrecursionlimit(10**9)
  input = sys.stdin.readline
  input_int = lambda: int(input())
  input_ints = lambda: map(int, input().split())
  input_ints_list = lambda: list(input_ints())
  input_str = lambda: input()
  input_strs = lambda: input().split()
  input_lines = lambda n, input_func: [input_func() for _ in range(n)]
  
  import importlib
  
  import_module = lambda module_name: importlib.import_module(module_name)
  
  init_array_1dim = lambda value, n: [value] * n  # 1次元配列を生成
  init_array_2dim = lambda value, n, m: [
      init_array_1dim(value, n) for _ in range(m)
  ]  # 2次元配列を生成
  
  gcd_base = lambda value1, value2: import_module("fractions").gcd(
      value1, value2
  )  # 最大公約数（2値)
  gcd = lambda lst: import_module("functools").reduce(
      gcd_base, lst
  )  # 最大公約数（リスト）
  lcm_base = lambda value1, value2: (value1 * value2) // gcd_base(
      value1, value2
  )  # 最小公倍数(2値)
  lcm = lambda lst: import_module("functools").reduce(
      lcm_base, lst, 1
  )  # 最小公倍数(リスト)
  
  permutations = lambda lst, n: import_module("itertools").permutations(lst, n)  # 順列
  combinations = lambda lst, n: import_module("itertools").combinations(
      lst, n
  )  # 組み合わせ
  product = lambda lst1, lst2: import_module("itertools").product(
      lst1, lst2
  )  # 二つのリストの直積
  
  round = lambda value: round(value)  # 四捨五入
  ceil = lambda value: import_module("math").ceil(value)  # 切り上げ
  floor = lambda value: import_module("math").floor(value)  # 切り捨て
  
  # キュー
  init_q = lambda lst: import_module("collections").deque(lst)
  q_pop = lambda q: q.popleft()  # 先頭から取り出し
  q_push = lambda q, value: q.appendleft(value)  # 先頭に追加（値）
  q_pushlist = lambda q, lst: q.extendleft(lst)  # 先頭に追加（リスト）
  q_append = lambda q, value: q.append(value)  # 末尾に追加（値）
  q_appendlist = lambda q, lst: q.extend(lst)  # 末尾に追加（リスト）
  
  # プライオリティキュー
  init_heap = lambda a: import_module("heapq").heapify(a)
  heap_push = lambda a, v: import_module("heapq").heappush(a, v)
  heap_pop = lambda a: import_module("heapq").heappop(a)  # 最小値を取り出す
  
  
  def solution():
      # ここに実装
      N, K = input_ints()
      h = input_ints_list()
  
      dp = init_array_1dim(0, N)
      for i in range(N):
          if i == 0:
              continue
          temp = []
          for j in range(K):
              if i - j - 1 < 0:
                  continue
              temp.append(dp[i - j - 1] + abs(h[i] - h[i - j - 1]))
          dp[i] = min(temp)
      print(dp[N - 1])
  
  
  if __name__ == "__main__":
      solution()
  
problem_description: Statement
  
  There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
  the height of Stone i is h_i.
  
  There is a frog who is initially on Stone 1. He will repeat the following
  action some number of times to reach Stone N:
  
    * If the frog is currently on Stone i, jump to one of the following: Stone i + 1, i + 2, \ldots, i + K. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
  
  Find the minimum possible total cost incurred before the frog reaches Stone N.
samples: [{"input": "5 3\n    10 30 40 50 20", "output": "30\n    \n\nIf we follow the path 1 \u2192 2 \u2192 5, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "3 1\n    10 20 10", "output": "20\n    \n\nIf we follow the path 1 \u2192 2 \u2192 3, the total cost incurred would be |10 - 20| +\n|20 - 10| = 20.\n\n* * *"}, {"input": "2 100\n    10 10", "output": "0\n    \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "10 4\n    40 10 20 70 80 10 20 70 80 60", "output": "40\n    \n\nIf we follow the path 1 \u2192 4 \u2192 8 \u2192 10, the total cost incurred would be |40 -\n70| + |70 - 70| + |70 - 60| = 40."}]