import java.util.Scanner;

public class Main {
	
	private static void solve(int n, int k,int[] h) {
		
		int[] dp = new int[n];
		for (int i=0; i<n; i++) {
			dp[i] = Integer.MAX_VALUE;
		}
		dp[0] = 0;
		
		for (int i=1; i<n; i++) {
			for (int j=1; j<=k && (i-j) >= 0; j++) {
				dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(h[i] - h[i-j]));
			}
		}
 
		System.out.println(dp[n-1]);
	}
 
	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		int k = scanner.nextInt();
		
		int[] h = new int[n];
		
		for (int i=0; i<n; i++) {
			h[i] = scanner.nextInt();
		}
		
		solve(n, k, h);
		
		scanner.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {
	
	private static void solve(int n, int k,int[] h) {
		
		int[] dp = new int[n];
		for (int i=0; i<n; i++) {
			dp[i] = Integer.MAX_VALUE;
		}
		dp[0] = 0;
		
		for (int i=1; i<n; i++) {
			for (int j=1; j<=k && (i-j) >= 0; j++) {
				dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(h[i] - h[i-j]));
			}
		}
 
		System.out.println(dp[n-1]);
	}
 
	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		int k = scanner.nextInt();
		
		int[] h = new int[n];
		
		for (int i=0; i<n; i++) {
			h[i] = scanner.nextInt();
		}
		
		solve(n, k, h);
		
		scanner.close();
	}
} Main private static void solve(int n, int k,int[] h) {
		
		int[] dp = new int[n];
		for (int i=0; i<n; i++) {
			dp[i] = Integer.MAX_VALUE;
		}
		dp[0] = 0;
		
		for (int i=1; i<n; i++) {
			for (int j=1; j<=k && (i-j) >= 0; j++) {
				dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(h[i] - h[i-j]));
			}
		}
 
		System.out.println(dp[n-1]);
	} solve {
		
		int[] dp = new int[n];
		for (int i=0; i<n; i++) {
			dp[i] = Integer.MAX_VALUE;
		}
		dp[0] = 0;
		
		for (int i=1; i<n; i++) {
			for (int j=1; j<=k && (i-j) >= 0; j++) {
				dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(h[i] - h[i-j]));
			}
		}
 
		System.out.println(dp[n-1]);
	} int[] dp = new int[n]; dp new int[n] n for (int i=0; i<n; i++) {
			dp[i] = Integer.MAX_VALUE;
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			dp[i] = Integer.MAX_VALUE;
		} {
			dp[i] = Integer.MAX_VALUE;
		} dp[i] = Integer.MAX_VALUE dp[i] dp i Integer.MAX_VALUE Integer Integer.MAX_VALUE dp[0] = 0 dp[0] dp 0 0 for (int i=1; i<n; i++) {
			for (int j=1; j<=k && (i-j) >= 0; j++) {
				dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(h[i] - h[i-j]));
			}
		} int i=1; int i=1; i 1 i<n i n i++ i++ i {
			for (int j=1; j<=k && (i-j) >= 0; j++) {
				dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(h[i] - h[i-j]));
			}
		} {
			for (int j=1; j<=k && (i-j) >= 0; j++) {
				dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(h[i] - h[i-j]));
			}
		} for (int j=1; j<=k && (i-j) >= 0; j++) {
				dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(h[i] - h[i-j]));
			} int j=1; int j=1; j 1 j<=k && (i-j) >= 0 j<=k j k (i-j) >= 0 (i-j) i j 0 j++ j++ j {
				dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(h[i] - h[i-j]));
			} {
				dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(h[i] - h[i-j]));
			} dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(h[i] - h[i-j])) dp[i] dp i Math.min(dp[i], dp[i-j] + Math.abs(h[i] - h[i-j])) Math.min Math dp[i] dp i dp[i-j] + Math.abs(h[i] - h[i-j]) dp[i-j] dp i-j i j Math.abs(h[i] - h[i-j]) Math.abs Math h[i] - h[i-j] h[i] h i h[i-j] h i-j i j System.out.println(dp[n-1]) System.out.println System.out System System.out dp[n-1] dp n-1 n 1 int n n int k k int[] h h public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		int k = scanner.nextInt();
		
		int[] h = new int[n];
		
		for (int i=0; i<n; i++) {
			h[i] = scanner.nextInt();
		}
		
		solve(n, k, h);
		
		scanner.close();
	} main {
		
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		int k = scanner.nextInt();
		
		int[] h = new int[n];
		
		for (int i=0; i<n; i++) {
			h[i] = scanner.nextInt();
		}
		
		solve(n, k, h);
		
		scanner.close();
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int k = scanner.nextInt(); k scanner.nextInt() scanner.nextInt scanner int[] h = new int[n]; h new int[n] n for (int i=0; i<n; i++) {
			h[i] = scanner.nextInt();
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			h[i] = scanner.nextInt();
		} {
			h[i] = scanner.nextInt();
		} h[i] = scanner.nextInt() h[i] h i scanner.nextInt() scanner.nextInt scanner solve(n, k, h) solve n k h scanner.close() scanner.close scanner String[] args args public class Main {
	
	private static void solve(int n, int k,int[] h) {
		
		int[] dp = new int[n];
		for (int i=0; i<n; i++) {
			dp[i] = Integer.MAX_VALUE;
		}
		dp[0] = 0;
		
		for (int i=1; i<n; i++) {
			for (int j=1; j<=k && (i-j) >= 0; j++) {
				dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(h[i] - h[i-j]));
			}
		}
 
		System.out.println(dp[n-1]);
	}
 
	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		int k = scanner.nextInt();
		
		int[] h = new int[n];
		
		for (int i=0; i<n; i++) {
			h[i] = scanner.nextInt();
		}
		
		solve(n, k, h);
		
		scanner.close();
	}
} public class Main {
	
	private static void solve(int n, int k,int[] h) {
		
		int[] dp = new int[n];
		for (int i=0; i<n; i++) {
			dp[i] = Integer.MAX_VALUE;
		}
		dp[0] = 0;
		
		for (int i=1; i<n; i++) {
			for (int j=1; j<=k && (i-j) >= 0; j++) {
				dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(h[i] - h[i-j]));
			}
		}
 
		System.out.println(dp[n-1]);
	}
 
	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		int k = scanner.nextInt();
		
		int[] h = new int[n];
		
		for (int i=0; i<n; i++) {
			h[i] = scanner.nextInt();
		}
		
		solve(n, k, h);
		
		scanner.close();
	}
} Main
import java.util.Scanner;

public class Main {
	
	private static void solve(int n, int k,int[] h) {
		
		int[] dp = new int[n];
		for (int i=0; i<n; i++) {
			dp[i] = Integer.MAX_VALUE;
		}
		dp[0] = 0;
		
		for (int i=1; i<n; i++) {
			for (int j=1; j<=k && (i-j) >= 0; j++) {
				dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(h[i] - h[i-j]));
			}
		}
 
		System.out.println(dp[n-1]);
	}
 
	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		int k = scanner.nextInt();
		
		int[] h = new int[n];
		
		for (int i=0; i<n; i++) {
			h[i] = scanner.nextInt();
		}
		
		solve(n, k, h);
		
		scanner.close();
	}
}