import java.util.*;
public class Main
{
  public static void main(String[] args )
  {
    Scanner scn = new Scanner(System.in) ;
    
    int n = scn.nextInt() ;
    
    int k = scn.nextInt() ;
    
    int[] arr =new int[n] ;
    
    for(int i =0 ; i < n; i++ ) arr[i] = scn.nextInt() ;
    
    
    if( n== 1 )
    {
     System.out.print(0) ; 
    }
    else{
    long[] dp = new long[n];
    
      dp[0] =  0 ; 
      //dp[1] =  (long)Math.abs(arr[1] - arr[0] ) ;
      
      for(int i =1 ; i < n; i++ )
      {
        long ans =  Long.MAX_VALUE ;
          
        
        for(int j = 1  ; j <= k ; j++ )
        {
         if( i-j < 0 ) break ;
          
          else{
           
            ans = Math.min(dp[i-j] + Math.abs(arr[i] - arr[i-j] ) ,ans ) ;
            
            
            }
          
        }
        dp[i] = ans  ;
        
        
     }
      
      System.out.print(dp[n-1]) ;
    
    }
    
    
    
  }
  
  
} import java.util.*; util.* java public class Main
{
  public static void main(String[] args )
  {
    Scanner scn = new Scanner(System.in) ;
    
    int n = scn.nextInt() ;
    
    int k = scn.nextInt() ;
    
    int[] arr =new int[n] ;
    
    for(int i =0 ; i < n; i++ ) arr[i] = scn.nextInt() ;
    
    
    if( n== 1 )
    {
     System.out.print(0) ; 
    }
    else{
    long[] dp = new long[n];
    
      dp[0] =  0 ; 
      //dp[1] =  (long)Math.abs(arr[1] - arr[0] ) ;
      
      for(int i =1 ; i < n; i++ )
      {
        long ans =  Long.MAX_VALUE ;
          
        
        for(int j = 1  ; j <= k ; j++ )
        {
         if( i-j < 0 ) break ;
          
          else{
           
            ans = Math.min(dp[i-j] + Math.abs(arr[i] - arr[i-j] ) ,ans ) ;
            
            
            }
          
        }
        dp[i] = ans  ;
        
        
     }
      
      System.out.print(dp[n-1]) ;
    
    }
    
    
    
  }
  
  
} Main public static void main(String[] args )
  {
    Scanner scn = new Scanner(System.in) ;
    
    int n = scn.nextInt() ;
    
    int k = scn.nextInt() ;
    
    int[] arr =new int[n] ;
    
    for(int i =0 ; i < n; i++ ) arr[i] = scn.nextInt() ;
    
    
    if( n== 1 )
    {
     System.out.print(0) ; 
    }
    else{
    long[] dp = new long[n];
    
      dp[0] =  0 ; 
      //dp[1] =  (long)Math.abs(arr[1] - arr[0] ) ;
      
      for(int i =1 ; i < n; i++ )
      {
        long ans =  Long.MAX_VALUE ;
          
        
        for(int j = 1  ; j <= k ; j++ )
        {
         if( i-j < 0 ) break ;
          
          else{
           
            ans = Math.min(dp[i-j] + Math.abs(arr[i] - arr[i-j] ) ,ans ) ;
            
            
            }
          
        }
        dp[i] = ans  ;
        
        
     }
      
      System.out.print(dp[n-1]) ;
    
    }
    
    
    
  } main {
    Scanner scn = new Scanner(System.in) ;
    
    int n = scn.nextInt() ;
    
    int k = scn.nextInt() ;
    
    int[] arr =new int[n] ;
    
    for(int i =0 ; i < n; i++ ) arr[i] = scn.nextInt() ;
    
    
    if( n== 1 )
    {
     System.out.print(0) ; 
    }
    else{
    long[] dp = new long[n];
    
      dp[0] =  0 ; 
      //dp[1] =  (long)Math.abs(arr[1] - arr[0] ) ;
      
      for(int i =1 ; i < n; i++ )
      {
        long ans =  Long.MAX_VALUE ;
          
        
        for(int j = 1  ; j <= k ; j++ )
        {
         if( i-j < 0 ) break ;
          
          else{
           
            ans = Math.min(dp[i-j] + Math.abs(arr[i] - arr[i-j] ) ,ans ) ;
            
            
            }
          
        }
        dp[i] = ans  ;
        
        
     }
      
      System.out.print(dp[n-1]) ;
    
    }
    
    
    
  } Scanner scn = new Scanner(System.in) ; scn new Scanner(System.in) int n = scn.nextInt() ; n scn.nextInt() scn.nextInt scn int k = scn.nextInt() ; k scn.nextInt() scn.nextInt scn int[] arr =new int[n] ; arr new int[n] n for(int i =0 ; i < n; i++ ) arr[i] = scn.nextInt() ; int i =0 ; int i =0 ; i 0 i < n i n i++ i++ i arr[i] = scn.nextInt() ; arr[i] = scn.nextInt() arr[i] arr i scn.nextInt() scn.nextInt scn if( n== 1 )
    {
     System.out.print(0) ; 
    }
    else{
    long[] dp = new long[n];
    
      dp[0] =  0 ; 
      //dp[1] =  (long)Math.abs(arr[1] - arr[0] ) ;
      
      for(int i =1 ; i < n; i++ )
      {
        long ans =  Long.MAX_VALUE ;
          
        
        for(int j = 1  ; j <= k ; j++ )
        {
         if( i-j < 0 ) break ;
          
          else{
           
            ans = Math.min(dp[i-j] + Math.abs(arr[i] - arr[i-j] ) ,ans ) ;
            
            
            }
          
        }
        dp[i] = ans  ;
        
        
     }
      
      System.out.print(dp[n-1]) ;
    
    } n== 1 n 1 {
     System.out.print(0) ; 
    } System.out.print(0) System.out.print System.out System System.out 0 {
    long[] dp = new long[n];
    
      dp[0] =  0 ; 
      //dp[1] =  (long)Math.abs(arr[1] - arr[0] ) ;
      
      for(int i =1 ; i < n; i++ )
      {
        long ans =  Long.MAX_VALUE ;
          
        
        for(int j = 1  ; j <= k ; j++ )
        {
         if( i-j < 0 ) break ;
          
          else{
           
            ans = Math.min(dp[i-j] + Math.abs(arr[i] - arr[i-j] ) ,ans ) ;
            
            
            }
          
        }
        dp[i] = ans  ;
        
        
     }
      
      System.out.print(dp[n-1]) ;
    
    } long[] dp = new long[n]; dp new long[n] n dp[0] =  0 dp[0] dp 0 0 for(int i =1 ; i < n; i++ )
      {
        long ans =  Long.MAX_VALUE ;
          
        
        for(int j = 1  ; j <= k ; j++ )
        {
         if( i-j < 0 ) break ;
          
          else{
           
            ans = Math.min(dp[i-j] + Math.abs(arr[i] - arr[i-j] ) ,ans ) ;
            
            
            }
          
        }
        dp[i] = ans  ;
        
        
     } int i =1 ; int i =1 ; i 1 i < n i n i++ i++ i {
        long ans =  Long.MAX_VALUE ;
          
        
        for(int j = 1  ; j <= k ; j++ )
        {
         if( i-j < 0 ) break ;
          
          else{
           
            ans = Math.min(dp[i-j] + Math.abs(arr[i] - arr[i-j] ) ,ans ) ;
            
            
            }
          
        }
        dp[i] = ans  ;
        
        
     } {
        long ans =  Long.MAX_VALUE ;
          
        
        for(int j = 1  ; j <= k ; j++ )
        {
         if( i-j < 0 ) break ;
          
          else{
           
            ans = Math.min(dp[i-j] + Math.abs(arr[i] - arr[i-j] ) ,ans ) ;
            
            
            }
          
        }
        dp[i] = ans  ;
        
        
     } long ans =  Long.MAX_VALUE ; ans Long.MAX_VALUE Long Long.MAX_VALUE for(int j = 1  ; j <= k ; j++ )
        {
         if( i-j < 0 ) break ;
          
          else{
           
            ans = Math.min(dp[i-j] + Math.abs(arr[i] - arr[i-j] ) ,ans ) ;
            
            
            }
          
        } int j = 1  ; int j = 1  ; j 1 j <= k j k j++ j++ j {
         if( i-j < 0 ) break ;
          
          else{
           
            ans = Math.min(dp[i-j] + Math.abs(arr[i] - arr[i-j] ) ,ans ) ;
            
            
            }
          
        } {
         if( i-j < 0 ) break ;
          
          else{
           
            ans = Math.min(dp[i-j] + Math.abs(arr[i] - arr[i-j] ) ,ans ) ;
            
            
            }
          
        } if( i-j < 0 ) break ;
          
          else{
           
            ans = Math.min(dp[i-j] + Math.abs(arr[i] - arr[i-j] ) ,ans ) ;
            
            
            } i-j < 0 i-j i j 0 break ; {
           
            ans = Math.min(dp[i-j] + Math.abs(arr[i] - arr[i-j] ) ,ans ) ;
            
            
            } ans = Math.min(dp[i-j] + Math.abs(arr[i] - arr[i-j] ) ,ans ) ans Math.min(dp[i-j] + Math.abs(arr[i] - arr[i-j] ) ,ans ) Math.min Math dp[i-j] + Math.abs(arr[i] - arr[i-j] ) dp[i-j] dp i-j i j Math.abs(arr[i] - arr[i-j] ) Math.abs Math arr[i] - arr[i-j] arr[i] arr i arr[i-j] arr i-j i j ans dp[i] = ans dp[i] dp i ans System.out.print(dp[n-1]) System.out.print System.out System System.out dp[n-1] dp n-1 n 1 String[] args args public class Main
{
  public static void main(String[] args )
  {
    Scanner scn = new Scanner(System.in) ;
    
    int n = scn.nextInt() ;
    
    int k = scn.nextInt() ;
    
    int[] arr =new int[n] ;
    
    for(int i =0 ; i < n; i++ ) arr[i] = scn.nextInt() ;
    
    
    if( n== 1 )
    {
     System.out.print(0) ; 
    }
    else{
    long[] dp = new long[n];
    
      dp[0] =  0 ; 
      //dp[1] =  (long)Math.abs(arr[1] - arr[0] ) ;
      
      for(int i =1 ; i < n; i++ )
      {
        long ans =  Long.MAX_VALUE ;
          
        
        for(int j = 1  ; j <= k ; j++ )
        {
         if( i-j < 0 ) break ;
          
          else{
           
            ans = Math.min(dp[i-j] + Math.abs(arr[i] - arr[i-j] ) ,ans ) ;
            
            
            }
          
        }
        dp[i] = ans  ;
        
        
     }
      
      System.out.print(dp[n-1]) ;
    
    }
    
    
    
  }
  
  
} public class Main
{
  public static void main(String[] args )
  {
    Scanner scn = new Scanner(System.in) ;
    
    int n = scn.nextInt() ;
    
    int k = scn.nextInt() ;
    
    int[] arr =new int[n] ;
    
    for(int i =0 ; i < n; i++ ) arr[i] = scn.nextInt() ;
    
    
    if( n== 1 )
    {
     System.out.print(0) ; 
    }
    else{
    long[] dp = new long[n];
    
      dp[0] =  0 ; 
      //dp[1] =  (long)Math.abs(arr[1] - arr[0] ) ;
      
      for(int i =1 ; i < n; i++ )
      {
        long ans =  Long.MAX_VALUE ;
          
        
        for(int j = 1  ; j <= k ; j++ )
        {
         if( i-j < 0 ) break ;
          
          else{
           
            ans = Math.min(dp[i-j] + Math.abs(arr[i] - arr[i-j] ) ,ans ) ;
            
            
            }
          
        }
        dp[i] = ans  ;
        
        
     }
      
      System.out.print(dp[n-1]) ;
    
    }
    
    
    
  }
  
  
} Main
import java.util.*;
public class Main
{
  public static void main(String[] args )
  {
    Scanner scn = new Scanner(System.in) ;
    
    int n = scn.nextInt() ;
    
    int k = scn.nextInt() ;
    
    int[] arr =new int[n] ;
    
    for(int i =0 ; i < n; i++ ) arr[i] = scn.nextInt() ;
    
    
    if( n== 1 )
    {
     System.out.print(0) ; 
    }
    else{
    long[] dp = new long[n];
    
      dp[0] =  0 ; 
      //dp[1] =  (long)Math.abs(arr[1] - arr[0] ) ;
      
      for(int i =1 ; i < n; i++ )
      {
        long ans =  Long.MAX_VALUE ;
          
        
        for(int j = 1  ; j <= k ; j++ )
        {
         if( i-j < 0 ) break ;
          
          else{
           
            ans = Math.min(dp[i-j] + Math.abs(arr[i] - arr[i-j] ) ,ans ) ;
            
            
            }
          
        }
        dp[i] = ans  ;
        
        
     }
      
      System.out.print(dp[n-1]) ;
    
    }
    
    
    
  }
  
  
}
