import java.util.Arrays;
import java.util.Scanner;

public class Main {
  public static void main (String[] args) {
    Scanner input = new Scanner(System.in);
    
    while (input.hasNext()) {
      int N = input.nextInt();
      int K = input.nextInt();
      int[] h = new int[N];
      
      for (int i = 0; i < h.length; ++i) {
        h[i] = input.nextInt();
      }
      
      int[] cost = new int[N];
      Arrays.fill(cost, Integer.MAX_VALUE);
      cost[0] = 0;
      for (int i = 0; i < h.length; ++i) {
        final int END = Math.min(h.length, i + K + 1);
        
        for (int j = i + 1; j < END; ++j) {
          cost[j] = Math.min(cost[j], cost[i] + Math.abs(h[j] - h[i]));
        }
      }
      
      System.out.println(cost[cost.length - 1]);
    }
  }
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
  public static void main (String[] args) {
    Scanner input = new Scanner(System.in);
    
    while (input.hasNext()) {
      int N = input.nextInt();
      int K = input.nextInt();
      int[] h = new int[N];
      
      for (int i = 0; i < h.length; ++i) {
        h[i] = input.nextInt();
      }
      
      int[] cost = new int[N];
      Arrays.fill(cost, Integer.MAX_VALUE);
      cost[0] = 0;
      for (int i = 0; i < h.length; ++i) {
        final int END = Math.min(h.length, i + K + 1);
        
        for (int j = i + 1; j < END; ++j) {
          cost[j] = Math.min(cost[j], cost[i] + Math.abs(h[j] - h[i]));
        }
      }
      
      System.out.println(cost[cost.length - 1]);
    }
  }
} Main public static void main (String[] args) {
    Scanner input = new Scanner(System.in);
    
    while (input.hasNext()) {
      int N = input.nextInt();
      int K = input.nextInt();
      int[] h = new int[N];
      
      for (int i = 0; i < h.length; ++i) {
        h[i] = input.nextInt();
      }
      
      int[] cost = new int[N];
      Arrays.fill(cost, Integer.MAX_VALUE);
      cost[0] = 0;
      for (int i = 0; i < h.length; ++i) {
        final int END = Math.min(h.length, i + K + 1);
        
        for (int j = i + 1; j < END; ++j) {
          cost[j] = Math.min(cost[j], cost[i] + Math.abs(h[j] - h[i]));
        }
      }
      
      System.out.println(cost[cost.length - 1]);
    }
  } main {
    Scanner input = new Scanner(System.in);
    
    while (input.hasNext()) {
      int N = input.nextInt();
      int K = input.nextInt();
      int[] h = new int[N];
      
      for (int i = 0; i < h.length; ++i) {
        h[i] = input.nextInt();
      }
      
      int[] cost = new int[N];
      Arrays.fill(cost, Integer.MAX_VALUE);
      cost[0] = 0;
      for (int i = 0; i < h.length; ++i) {
        final int END = Math.min(h.length, i + K + 1);
        
        for (int j = i + 1; j < END; ++j) {
          cost[j] = Math.min(cost[j], cost[i] + Math.abs(h[j] - h[i]));
        }
      }
      
      System.out.println(cost[cost.length - 1]);
    }
  } Scanner input = new Scanner(System.in); input new Scanner(System.in) while (input.hasNext()) {
      int N = input.nextInt();
      int K = input.nextInt();
      int[] h = new int[N];
      
      for (int i = 0; i < h.length; ++i) {
        h[i] = input.nextInt();
      }
      
      int[] cost = new int[N];
      Arrays.fill(cost, Integer.MAX_VALUE);
      cost[0] = 0;
      for (int i = 0; i < h.length; ++i) {
        final int END = Math.min(h.length, i + K + 1);
        
        for (int j = i + 1; j < END; ++j) {
          cost[j] = Math.min(cost[j], cost[i] + Math.abs(h[j] - h[i]));
        }
      }
      
      System.out.println(cost[cost.length - 1]);
    } input.hasNext() input.hasNext input {
      int N = input.nextInt();
      int K = input.nextInt();
      int[] h = new int[N];
      
      for (int i = 0; i < h.length; ++i) {
        h[i] = input.nextInt();
      }
      
      int[] cost = new int[N];
      Arrays.fill(cost, Integer.MAX_VALUE);
      cost[0] = 0;
      for (int i = 0; i < h.length; ++i) {
        final int END = Math.min(h.length, i + K + 1);
        
        for (int j = i + 1; j < END; ++j) {
          cost[j] = Math.min(cost[j], cost[i] + Math.abs(h[j] - h[i]));
        }
      }
      
      System.out.println(cost[cost.length - 1]);
    } int N = input.nextInt(); N input.nextInt() input.nextInt input int K = input.nextInt(); K input.nextInt() input.nextInt input int[] h = new int[N]; h new int[N] N for (int i = 0; i < h.length; ++i) {
        h[i] = input.nextInt();
      } int i = 0; int i = 0; i 0 i < h.length i h.length h h.length ++i ++i i {
        h[i] = input.nextInt();
      } {
        h[i] = input.nextInt();
      } h[i] = input.nextInt() h[i] h i input.nextInt() input.nextInt input int[] cost = new int[N]; cost new int[N] N Arrays.fill(cost, Integer.MAX_VALUE) Arrays.fill Arrays cost Integer.MAX_VALUE Integer Integer.MAX_VALUE cost[0] = 0 cost[0] cost 0 0 for (int i = 0; i < h.length; ++i) {
        final int END = Math.min(h.length, i + K + 1);
        
        for (int j = i + 1; j < END; ++j) {
          cost[j] = Math.min(cost[j], cost[i] + Math.abs(h[j] - h[i]));
        }
      } int i = 0; int i = 0; i 0 i < h.length i h.length h h.length ++i ++i i {
        final int END = Math.min(h.length, i + K + 1);
        
        for (int j = i + 1; j < END; ++j) {
          cost[j] = Math.min(cost[j], cost[i] + Math.abs(h[j] - h[i]));
        }
      } {
        final int END = Math.min(h.length, i + K + 1);
        
        for (int j = i + 1; j < END; ++j) {
          cost[j] = Math.min(cost[j], cost[i] + Math.abs(h[j] - h[i]));
        }
      } final int END = Math.min(h.length, i + K + 1); END Math.min(h.length, i + K + 1) Math.min Math h.length h h.length i + K + 1 i + K + 1 i K 1 for (int j = i + 1; j < END; ++j) {
          cost[j] = Math.min(cost[j], cost[i] + Math.abs(h[j] - h[i]));
        } int j = i + 1; int j = i + 1; j i + 1 i 1 j < END j END ++j ++j j {
          cost[j] = Math.min(cost[j], cost[i] + Math.abs(h[j] - h[i]));
        } {
          cost[j] = Math.min(cost[j], cost[i] + Math.abs(h[j] - h[i]));
        } cost[j] = Math.min(cost[j], cost[i] + Math.abs(h[j] - h[i])) cost[j] cost j Math.min(cost[j], cost[i] + Math.abs(h[j] - h[i])) Math.min Math cost[j] cost j cost[i] + Math.abs(h[j] - h[i]) cost[i] cost i Math.abs(h[j] - h[i]) Math.abs Math h[j] - h[i] h[j] h j h[i] h i System.out.println(cost[cost.length - 1]) System.out.println System.out System System.out cost[cost.length - 1] cost cost.length - 1 cost.length cost cost.length 1 String[] args args public class Main {
  public static void main (String[] args) {
    Scanner input = new Scanner(System.in);
    
    while (input.hasNext()) {
      int N = input.nextInt();
      int K = input.nextInt();
      int[] h = new int[N];
      
      for (int i = 0; i < h.length; ++i) {
        h[i] = input.nextInt();
      }
      
      int[] cost = new int[N];
      Arrays.fill(cost, Integer.MAX_VALUE);
      cost[0] = 0;
      for (int i = 0; i < h.length; ++i) {
        final int END = Math.min(h.length, i + K + 1);
        
        for (int j = i + 1; j < END; ++j) {
          cost[j] = Math.min(cost[j], cost[i] + Math.abs(h[j] - h[i]));
        }
      }
      
      System.out.println(cost[cost.length - 1]);
    }
  }
} public class Main {
  public static void main (String[] args) {
    Scanner input = new Scanner(System.in);
    
    while (input.hasNext()) {
      int N = input.nextInt();
      int K = input.nextInt();
      int[] h = new int[N];
      
      for (int i = 0; i < h.length; ++i) {
        h[i] = input.nextInt();
      }
      
      int[] cost = new int[N];
      Arrays.fill(cost, Integer.MAX_VALUE);
      cost[0] = 0;
      for (int i = 0; i < h.length; ++i) {
        final int END = Math.min(h.length, i + K + 1);
        
        for (int j = i + 1; j < END; ++j) {
          cost[j] = Math.min(cost[j], cost[i] + Math.abs(h[j] - h[i]));
        }
      }
      
      System.out.println(cost[cost.length - 1]);
    }
  }
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  public static void main (String[] args) {
    Scanner input = new Scanner(System.in);
    
    while (input.hasNext()) {
      int N = input.nextInt();
      int K = input.nextInt();
      int[] h = new int[N];
      
      for (int i = 0; i < h.length; ++i) {
        h[i] = input.nextInt();
      }
      
      int[] cost = new int[N];
      Arrays.fill(cost, Integer.MAX_VALUE);
      cost[0] = 0;
      for (int i = 0; i < h.length; ++i) {
        final int END = Math.min(h.length, i + K + 1);
        
        for (int j = i + 1; j < END; ++j) {
          cost[j] = Math.min(cost[j], cost[i] + Math.abs(h[j] - h[i]));
        }
      }
      
      System.out.println(cost[cost.length - 1]);
    }
  }
}