import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] h = new int[n];
		long[] dp = new long[n];
		for(int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			dp[i] = 9223372036854775807l;
		}
		
		dp[0] = 0;
		for(int i = 1;i < n; i++) {
			for(int m = 1; m < k+1; m++) {
				if(i >= m )dp[i] = Math.min(dp[i], dp[i-m] + Math.abs(h[i] - h[i - m]));
			}
		}
		System.out.println(dp[n - 1]);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] h = new int[n];
		long[] dp = new long[n];
		for(int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			dp[i] = 9223372036854775807l;
		}
		
		dp[0] = 0;
		for(int i = 1;i < n; i++) {
			for(int m = 1; m < k+1; m++) {
				if(i >= m )dp[i] = Math.min(dp[i], dp[i-m] + Math.abs(h[i] - h[i - m]));
			}
		}
		System.out.println(dp[n - 1]);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] h = new int[n];
		long[] dp = new long[n];
		for(int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			dp[i] = 9223372036854775807l;
		}
		
		dp[0] = 0;
		for(int i = 1;i < n; i++) {
			for(int m = 1; m < k+1; m++) {
				if(i >= m )dp[i] = Math.min(dp[i], dp[i-m] + Math.abs(h[i] - h[i - m]));
			}
		}
		System.out.println(dp[n - 1]);
	} main {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] h = new int[n];
		long[] dp = new long[n];
		for(int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			dp[i] = 9223372036854775807l;
		}
		
		dp[0] = 0;
		for(int i = 1;i < n; i++) {
			for(int m = 1; m < k+1; m++) {
				if(i >= m )dp[i] = Math.min(dp[i], dp[i-m] + Math.abs(h[i] - h[i - m]));
			}
		}
		System.out.println(dp[n - 1]);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int k = sc.nextInt(); k sc.nextInt() sc.nextInt sc int[] h = new int[n]; h new int[n] n long[] dp = new long[n]; dp new long[n] n for(int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			dp[i] = 9223372036854775807l;
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			h[i] = sc.nextInt();
			dp[i] = 9223372036854775807l;
		} {
			h[i] = sc.nextInt();
			dp[i] = 9223372036854775807l;
		} h[i] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc dp[i] = 9223372036854775807l dp[i] dp i 9223372036854775807l dp[0] = 0 dp[0] dp 0 0 for(int i = 1;i < n; i++) {
			for(int m = 1; m < k+1; m++) {
				if(i >= m )dp[i] = Math.min(dp[i], dp[i-m] + Math.abs(h[i] - h[i - m]));
			}
		} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
			for(int m = 1; m < k+1; m++) {
				if(i >= m )dp[i] = Math.min(dp[i], dp[i-m] + Math.abs(h[i] - h[i - m]));
			}
		} {
			for(int m = 1; m < k+1; m++) {
				if(i >= m )dp[i] = Math.min(dp[i], dp[i-m] + Math.abs(h[i] - h[i - m]));
			}
		} for(int m = 1; m < k+1; m++) {
				if(i >= m )dp[i] = Math.min(dp[i], dp[i-m] + Math.abs(h[i] - h[i - m]));
			} int m = 1; int m = 1; m 1 m < k+1 m k+1 k 1 m++ m++ m {
				if(i >= m )dp[i] = Math.min(dp[i], dp[i-m] + Math.abs(h[i] - h[i - m]));
			} {
				if(i >= m )dp[i] = Math.min(dp[i], dp[i-m] + Math.abs(h[i] - h[i - m]));
			} if(i >= m )dp[i] = Math.min(dp[i], dp[i-m] + Math.abs(h[i] - h[i - m])); i >= m i m dp[i] = Math.min(dp[i], dp[i-m] + Math.abs(h[i] - h[i - m])) dp[i] dp i Math.min(dp[i], dp[i-m] + Math.abs(h[i] - h[i - m])) Math.min Math dp[i] dp i dp[i-m] + Math.abs(h[i] - h[i - m]) dp[i-m] dp i-m i m Math.abs(h[i] - h[i - m]) Math.abs Math h[i] - h[i - m] h[i] h i h[i - m] h i - m i m System.out.println(dp[n - 1]) System.out.println 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 sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] h = new int[n];
		long[] dp = new long[n];
		for(int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			dp[i] = 9223372036854775807l;
		}
		
		dp[0] = 0;
		for(int i = 1;i < n; i++) {
			for(int m = 1; m < k+1; m++) {
				if(i >= m )dp[i] = Math.min(dp[i], dp[i-m] + Math.abs(h[i] - h[i - m]));
			}
		}
		System.out.println(dp[n - 1]);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] h = new int[n];
		long[] dp = new long[n];
		for(int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			dp[i] = 9223372036854775807l;
		}
		
		dp[0] = 0;
		for(int i = 1;i < n; i++) {
			for(int m = 1; m < k+1; m++) {
				if(i >= m )dp[i] = Math.min(dp[i], dp[i-m] + Math.abs(h[i] - h[i - m]));
			}
		}
		System.out.println(dp[n - 1]);
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] h = new int[n];
		long[] dp = new long[n];
		for(int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			dp[i] = 9223372036854775807l;
		}
		
		dp[0] = 0;
		for(int i = 1;i < n; i++) {
			for(int m = 1; m < k+1; m++) {
				if(i >= m )dp[i] = Math.min(dp[i], dp[i-m] + Math.abs(h[i] - h[i - m]));
			}
		}
		System.out.println(dp[n - 1]);
	}
}