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: import sys
  sys.setrecursionlimit(2000000001)
  
  def solve(n,k,ar,dp,x):
  	ab = abs; mn = min
      if x>=n-2: return dp[x]
  	if dp[x] != -1: return dp[x]
  	m = 1e9
  	for i in range(x+1,mn(n,x+k+1)):
  		t = ab(ar[x]-ar[i])+solve(n,k,ar,dp,i)
  		m = t if t<m else m
  	dp[x] = m
  	# pr(f'{x} => {dp[x]}')
  	return dp[x]
  
  def main():
  	I = lambda:map(int,sys.stdin.readline().split())
  	pr = lambda x:sys.stdout.write(f'{x}\n')
  	n,k, ar = *I(), [*I()]
  	dp = [-1]*(n-2) + [abs(ar[-2]-ar[-1]),0]
  	# pr((n,k,ar,dp))
  	pr(solve(n,k,ar,dp,0))
  
  main()
  
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."}]