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: #!/usr/bin/env python
  # coding: utf-8
  import sys
  
  # N, K = 5, 3
  # h = list(map(int, "10 30 40 50 20".split()))
  N, K = list(map(int, sys.stdin.readline().split()))
  h = list(map(int, sys.stdin.readline().split()))
  
  
  def test1():
      dp = {0: 0.0}
  
      def sget(i) -> float:
          if i in dp:
              return dp[i]
          return float("inf")
  
      def hs(i, j) -> float:
          return abs(h[i] - h[j])
  
      for i in range(1, N):
          value = float("inf")
          for k in range(1, K + 1):
              if i - k < 0:
                  continue
              # value = min(value, hs(i, i - k) + sget(i - k))
              if i - k not in dp:
                  continue
              value = min(value, abs(h[i] - h[i - k]) + dp[i - k])
          dp[i] = value
  
      print(int(dp[N - 1]))
  
  
  def test2():
      MAXN = 100002
      dp = [-1] * MAXN
      dp[1] = 0
  
      def hs(i, j):
          return abs(h[i - 1] - h[j - 1])
  
      for i in range(2, K + 1):
          for j in range(1, i):
              if dp[i] == -1 or dp[j] + hs(i, j) < dp[i]:
                  dp[i] = dp[j] + hs(i, j)
  
      for i in range(K + 1, N + 1):
          for j in range(i - K, i):
              if dp[i] == -1 or dp[j] + hs(i, j) < dp[i]:
                  dp[i] = dp[j] + hs(i, j)
  
      print(dp[N])
  
  
  def test3():
      INF = 10**5
      dp = [0] * (N + 1)
      for i in range(2, N + 1):
          dp[i] = INF
          for j in range(i - 1, 0, -1):
              if j < i - K:
                  break
              dp[i] = min(dp[i], dp[j] + abs(h[i - 1] - h[j - 1]))
      print(dp[N])
  
  
  test3()
  
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."}]