import java.io.*;
import java.util.*;


class Solver {            
    StringBuilder out=new StringBuilder(100);
    FastReader in=new FastReader();
    public long pow(long a, long b){
        if(b==0)return 1;
            long ans=pow(a,b/2);
            ans*=ans;
            ans%=mod;
        if(b%2==1){
            ans*=a;
            ans%=mod;
        }
        return ans;
    }
    
    public int[] getIntArray(int n){
        int arr[]=new int[n];
        for(int i=0;i<n;i++){
            arr[i]=in.nextInt();
        }
        return arr;
    }

    int  mod=(int)(1e9 + 7);
    
    public void solve(){
        int n=in.nextInt(),k=in.nextInt();
        int arr[]=getIntArray(n);
        int dp[]=new int[n+1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0]=0;
        for(int i=0;i<n;i++){
            for(int j=1;j<=k && i+j<n;j++){
                dp[i+j]=Math.min(dp[i+j], dp[i]+Math.abs(arr[i]-arr[i+j]));
            }
        }
        out.append(dp[n-1]);
    }
    public void run(){
        int t=1;
        for(int i=0;i<t;i++){
            solve();
            out.append('\n');
        }
        System.out.println(out);
    }
}
    
    
    
    
    
/////////////////////
    
    
    
    
    
    
    public class Main{
        public static void main(String args[]){
            Solver s=new Solver();
            s.run();
        }
    } 
    
    class FastReader { 
        final private int BUFFER_SIZE = 1 << 16; 
        private DataInputStream din; 
        private byte[] buffer; 
        private int bufferPointer, bytesRead; 
    
        public FastReader() { 
            din = new DataInputStream(System.in); 
            buffer = new byte[BUFFER_SIZE]; 
            bufferPointer = bytesRead = 0; 
        } 
    
        public FastReader(String file_name) throws IOException{ 
            din = new DataInputStream(new FileInputStream(file_name)); 
            buffer = new byte[BUFFER_SIZE]; 
            bufferPointer = bytesRead = 0; 
        } 
    
        public String nextLine() { 
            try{
                byte[] buf = new byte[10000000]; // line length 
                int cnt = 0, c; 
                while ((c = read()) != -1) { 
                    if (c == '\n') 
                        break; 
                    buf[cnt++] = (byte) c; 
                } 
                return new String(buf, 0, cnt); 
            }catch (Exception e){
                System.out.println(e.getMessage());
                return null;
            }
        } 
    
        public int nextInt()  { 
            int ret = 0; 
            try {
                byte c = read(); 
                while (c <= ' ') 
                    c = read(); 
                boolean neg = (c == '-'); 
                if (neg) c = read(); 
                do{ 
                    ret = ret * 10 + c - '0'; 
                }  while ((c = read()) >= '0' && c <= '9'); 
    
                if (neg) return -ret; 
                return ret; 
            } catch (Exception e) {
                System.out.println(e.getMessage());
                return -1;
            }
        } 
    
        public long nextLong()   { 
            
            try {
                long ret = 0; 
                byte c = read(); 
                while (c <= ' ') c = read(); 
                boolean neg = (c == '-'); 
                if (neg) 
                    c = read(); 
                do { 
                    ret = ret * 10 + c - '0'; 
                } 
                while ((c = read()) >= '0' && c <= '9'); 
                if (neg) 
                    return -ret; 
                return ret;
            } catch (Exception e) {
                System.out.println(e.getMessage());
                return -1;
            }
        } 
    
        public double nextDouble()  { 
            
            try {
                double ret = 0, div = 1; 
                byte c = read(); 
                while (c <= ' ') 
                    c = read(); 
                boolean neg = (c == '-'); 
                if (neg) c = read(); 
    
                do { 
                    ret = ret * 10 + c - '0'; 
                } 
                while ((c = read()) >= '0' && c <= '9'); 
                if (c == '.') { 
                    while ((c = read()) >= '0' && c <= '9') { 
                        ret += (c - '0') / (div *= 10); 
                    } 
                } 
    
                if (neg) return -ret; 
                return ret;
            } catch (Exception e) {
                System.out.println(e.getMessage());
                return -1;
            }
        } 
    
        private void fillBuffer() throws IOException{ 
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); 
            if (bytesRead == -1) 
                buffer[0] = -1; 
        } 
    
        private byte read() throws IOException  { 
            try{
                if (bufferPointer == bytesRead) 
                    fillBuffer(); 
                return buffer[bufferPointer++]; 
            }catch(Exception e){
                System.out.println(e.getMessage());
                return -1;
            }
        } 
    
        public void close() throws IOException { 
            if (din == null) 
                return; 
            din.close(); 
        } 
    } 


    // class FastReader {
    //     BufferedReader br;
    //     StringTokenizer st;
    
    //     public FastReader() {
    //         br = new BufferedReader(new InputStreamReader(System.in));
    //     }
    
    //     String next() {
    //         while (st == null || !st.hasMoreElements()) {
    //             try {
    //                 st = new StringTokenizer(br.readLine());
    //             } catch (IOException e) {
    //                 e.printStackTrace();
    //             }
    //         }
    //         return st.nextToken();
    //     }
    
    //     int nextInt() {
    //         return Integer.parseInt(next());
    //     }
    
    //     long nextLong() {
    //         return Long.parseLong(next());
    //     }
    
    //     double nextDouble() {
    //         return Double.parseDouble(next());
    //     }
    
    //     String nextLine() {
    //         String str = "";
    //         try {
    //             str = br.readLine();
    //         } catch (IOException e) {
    //             e.printStackTrace();
    //         }
    //         return str;
    //     }
    // } import java.io.*; io.* java import java.util.*; util.* java class Solver {            
    StringBuilder out=new StringBuilder(100);
    FastReader in=new FastReader();
    public long pow(long a, long b){
        if(b==0)return 1;
            long ans=pow(a,b/2);
            ans*=ans;
            ans%=mod;
        if(b%2==1){
            ans*=a;
            ans%=mod;
        }
        return ans;
    }
    
    public int[] getIntArray(int n){
        int arr[]=new int[n];
        for(int i=0;i<n;i++){
            arr[i]=in.nextInt();
        }
        return arr;
    }

    int  mod=(int)(1e9 + 7);
    
    public void solve(){
        int n=in.nextInt(),k=in.nextInt();
        int arr[]=getIntArray(n);
        int dp[]=new int[n+1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0]=0;
        for(int i=0;i<n;i++){
            for(int j=1;j<=k && i+j<n;j++){
                dp[i+j]=Math.min(dp[i+j], dp[i]+Math.abs(arr[i]-arr[i+j]));
            }
        }
        out.append(dp[n-1]);
    }
    public void run(){
        int t=1;
        for(int i=0;i<t;i++){
            solve();
            out.append('\n');
        }
        System.out.println(out);
    }
} Solver StringBuilder out=new StringBuilder(100); out new StringBuilder(100) FastReader in=new FastReader(); in new FastReader() int  mod=(int)(1e9 + 7); mod (int)(1e9 + 7) 1e9 7 public long pow(long a, long b){
        if(b==0)return 1;
            long ans=pow(a,b/2);
            ans*=ans;
            ans%=mod;
        if(b%2==1){
            ans*=a;
            ans%=mod;
        }
        return ans;
    } pow {
        if(b==0)return 1;
            long ans=pow(a,b/2);
            ans*=ans;
            ans%=mod;
        if(b%2==1){
            ans*=a;
            ans%=mod;
        }
        return ans;
    } if(b==0)return 1; b==0 b 0 return 1; 1 long ans=pow(a,b/2); ans pow(a,b/2) pow a b/2 b 2 ans*=ans ans ans ans%=mod ans mod if(b%2==1){
            ans*=a;
            ans%=mod;
        } b%2==1 b%2 b 2 1 {
            ans*=a;
            ans%=mod;
        } ans*=a ans a ans%=mod ans mod return ans; ans long a a long b b public int[] getIntArray(int n){
        int arr[]=new int[n];
        for(int i=0;i<n;i++){
            arr[i]=in.nextInt();
        }
        return arr;
    } getIntArray {
        int arr[]=new int[n];
        for(int i=0;i<n;i++){
            arr[i]=in.nextInt();
        }
        return arr;
    } int arr[]=new int[n]; arr new int[n] n for(int i=0;i<n;i++){
            arr[i]=in.nextInt();
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            arr[i]=in.nextInt();
        } {
            arr[i]=in.nextInt();
        } arr[i]=in.nextInt() arr[i] arr i in.nextInt() in.nextInt in return arr; arr int n n public void solve(){
        int n=in.nextInt(),k=in.nextInt();
        int arr[]=getIntArray(n);
        int dp[]=new int[n+1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0]=0;
        for(int i=0;i<n;i++){
            for(int j=1;j<=k && i+j<n;j++){
                dp[i+j]=Math.min(dp[i+j], dp[i]+Math.abs(arr[i]-arr[i+j]));
            }
        }
        out.append(dp[n-1]);
    } solve {
        int n=in.nextInt(),k=in.nextInt();
        int arr[]=getIntArray(n);
        int dp[]=new int[n+1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0]=0;
        for(int i=0;i<n;i++){
            for(int j=1;j<=k && i+j<n;j++){
                dp[i+j]=Math.min(dp[i+j], dp[i]+Math.abs(arr[i]-arr[i+j]));
            }
        }
        out.append(dp[n-1]);
    } int n=in.nextInt() n in.nextInt() in.nextInt in k=in.nextInt(); k in.nextInt() in.nextInt in int arr[]=getIntArray(n); arr getIntArray(n) getIntArray n int dp[]=new int[n+1]; dp new int[n+1] n+1 n 1 Arrays.fill(dp, Integer.MAX_VALUE) Arrays.fill Arrays dp Integer.MAX_VALUE Integer Integer.MAX_VALUE dp[0]=0 dp[0] dp 0 0 for(int i=0;i<n;i++){
            for(int j=1;j<=k && i+j<n;j++){
                dp[i+j]=Math.min(dp[i+j], dp[i]+Math.abs(arr[i]-arr[i+j]));
            }
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            for(int j=1;j<=k && i+j<n;j++){
                dp[i+j]=Math.min(dp[i+j], dp[i]+Math.abs(arr[i]-arr[i+j]));
            }
        } {
            for(int j=1;j<=k && i+j<n;j++){
                dp[i+j]=Math.min(dp[i+j], dp[i]+Math.abs(arr[i]-arr[i+j]));
            }
        } for(int j=1;j<=k && i+j<n;j++){
                dp[i+j]=Math.min(dp[i+j], dp[i]+Math.abs(arr[i]-arr[i+j]));
            } int j=1; int j=1; j 1 j<=k && i+j<n j<=k j k i+j<n i+j i j n j++ j++ j {
                dp[i+j]=Math.min(dp[i+j], dp[i]+Math.abs(arr[i]-arr[i+j]));
            } {
                dp[i+j]=Math.min(dp[i+j], dp[i]+Math.abs(arr[i]-arr[i+j]));
            } dp[i+j]=Math.min(dp[i+j], dp[i]+Math.abs(arr[i]-arr[i+j])) dp[i+j] dp i+j i j Math.min(dp[i+j], dp[i]+Math.abs(arr[i]-arr[i+j])) Math.min Math dp[i+j] dp i+j i j dp[i]+Math.abs(arr[i]-arr[i+j]) dp[i] dp i 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 out.append(dp[n-1]) out.append out dp[n-1] dp n-1 n 1 public void run(){
        int t=1;
        for(int i=0;i<t;i++){
            solve();
            out.append('\n');
        }
        System.out.println(out);
    } run {
        int t=1;
        for(int i=0;i<t;i++){
            solve();
            out.append('\n');
        }
        System.out.println(out);
    } int t=1; t 1 for(int i=0;i<t;i++){
            solve();
            out.append('\n');
        } int i=0; int i=0; i 0 i<t i t i++ i++ i {
            solve();
            out.append('\n');
        } {
            solve();
            out.append('\n');
        } solve() solve out.append('\n') out.append out '\n' System.out.println(out) System.out.println System.out System System.out out public class Main{
        public static void main(String args[]){
            Solver s=new Solver();
            s.run();
        }
    } Main public static void main(String args[]){
            Solver s=new Solver();
            s.run();
        } main {
            Solver s=new Solver();
            s.run();
        } Solver s=new Solver(); s new Solver() s.run() s.run s String args[] args class FastReader { 
        final private int BUFFER_SIZE = 1 << 16; 
        private DataInputStream din; 
        private byte[] buffer; 
        private int bufferPointer, bytesRead; 
    
        public FastReader() { 
            din = new DataInputStream(System.in); 
            buffer = new byte[BUFFER_SIZE]; 
            bufferPointer = bytesRead = 0; 
        } 
    
        public FastReader(String file_name) throws IOException{ 
            din = new DataInputStream(new FileInputStream(file_name)); 
            buffer = new byte[BUFFER_SIZE]; 
            bufferPointer = bytesRead = 0; 
        } 
    
        public String nextLine() { 
            try{
                byte[] buf = new byte[10000000]; // line length 
                int cnt = 0, c; 
                while ((c = read()) != -1) { 
                    if (c == '\n') 
                        break; 
                    buf[cnt++] = (byte) c; 
                } 
                return new String(buf, 0, cnt); 
            }catch (Exception e){
                System.out.println(e.getMessage());
                return null;
            }
        } 
    
        public int nextInt()  { 
            int ret = 0; 
            try {
                byte c = read(); 
                while (c <= ' ') 
                    c = read(); 
                boolean neg = (c == '-'); 
                if (neg) c = read(); 
                do{ 
                    ret = ret * 10 + c - '0'; 
                }  while ((c = read()) >= '0' && c <= '9'); 
    
                if (neg) return -ret; 
                return ret; 
            } catch (Exception e) {
                System.out.println(e.getMessage());
                return -1;
            }
        } 
    
        public long nextLong()   { 
            
            try {
                long ret = 0; 
                byte c = read(); 
                while (c <= ' ') c = read(); 
                boolean neg = (c == '-'); 
                if (neg) 
                    c = read(); 
                do { 
                    ret = ret * 10 + c - '0'; 
                } 
                while ((c = read()) >= '0' && c <= '9'); 
                if (neg) 
                    return -ret; 
                return ret;
            } catch (Exception e) {
                System.out.println(e.getMessage());
                return -1;
            }
        } 
    
        public double nextDouble()  { 
            
            try {
                double ret = 0, div = 1; 
                byte c = read(); 
                while (c <= ' ') 
                    c = read(); 
                boolean neg = (c == '-'); 
                if (neg) c = read(); 
    
                do { 
                    ret = ret * 10 + c - '0'; 
                } 
                while ((c = read()) >= '0' && c <= '9'); 
                if (c == '.') { 
                    while ((c = read()) >= '0' && c <= '9') { 
                        ret += (c - '0') / (div *= 10); 
                    } 
                } 
    
                if (neg) return -ret; 
                return ret;
            } catch (Exception e) {
                System.out.println(e.getMessage());
                return -1;
            }
        } 
    
        private void fillBuffer() throws IOException{ 
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); 
            if (bytesRead == -1) 
                buffer[0] = -1; 
        } 
    
        private byte read() throws IOException  { 
            try{
                if (bufferPointer == bytesRead) 
                    fillBuffer(); 
                return buffer[bufferPointer++]; 
            }catch(Exception e){
                System.out.println(e.getMessage());
                return -1;
            }
        } 
    
        public void close() throws IOException { 
            if (din == null) 
                return; 
            din.close(); 
        } 
    } FastReader final private int BUFFER_SIZE = 1 << 16; BUFFER_SIZE 1 << 16 1 16 private DataInputStream din; din private byte[] buffer; buffer private int bufferPointer bufferPointer bytesRead; bytesRead public FastReader() { 
            din = new DataInputStream(System.in); 
            buffer = new byte[BUFFER_SIZE]; 
            bufferPointer = bytesRead = 0; 
        } FastReader { 
            din = new DataInputStream(System.in); 
            buffer = new byte[BUFFER_SIZE]; 
            bufferPointer = bytesRead = 0; 
        } din = new DataInputStream(System.in) din new DataInputStream(System.in) buffer = new byte[BUFFER_SIZE] buffer new byte[BUFFER_SIZE] BUFFER_SIZE bufferPointer = bytesRead = 0 bufferPointer bytesRead = 0 bytesRead 0 public FastReader(String file_name) throws IOException{ 
            din = new DataInputStream(new FileInputStream(file_name)); 
            buffer = new byte[BUFFER_SIZE]; 
            bufferPointer = bytesRead = 0; 
        } FastReader { 
            din = new DataInputStream(new FileInputStream(file_name)); 
            buffer = new byte[BUFFER_SIZE]; 
            bufferPointer = bytesRead = 0; 
        } din = new DataInputStream(new FileInputStream(file_name)) din new DataInputStream(new FileInputStream(file_name)) buffer = new byte[BUFFER_SIZE] buffer new byte[BUFFER_SIZE] BUFFER_SIZE bufferPointer = bytesRead = 0 bufferPointer bytesRead = 0 bytesRead 0 String file_name file_name public String nextLine() { 
            try{
                byte[] buf = new byte[10000000]; // line length 
                int cnt = 0, c; 
                while ((c = read()) != -1) { 
                    if (c == '\n') 
                        break; 
                    buf[cnt++] = (byte) c; 
                } 
                return new String(buf, 0, cnt); 
            }catch (Exception e){
                System.out.println(e.getMessage());
                return null;
            }
        } nextLine { 
            try{
                byte[] buf = new byte[10000000]; // line length 
                int cnt = 0, c; 
                while ((c = read()) != -1) { 
                    if (c == '\n') 
                        break; 
                    buf[cnt++] = (byte) c; 
                } 
                return new String(buf, 0, cnt); 
            }catch (Exception e){
                System.out.println(e.getMessage());
                return null;
            }
        } try{
                byte[] buf = new byte[10000000]; // line length 
                int cnt = 0, c; 
                while ((c = read()) != -1) { 
                    if (c == '\n') 
                        break; 
                    buf[cnt++] = (byte) c; 
                } 
                return new String(buf, 0, cnt); 
            }catch (Exception e){
                System.out.println(e.getMessage());
                return null;
            } catch (Exception e){
                System.out.println(e.getMessage());
                return null;
            } Exception e {
                System.out.println(e.getMessage());
                return null;
            } System.out.println(e.getMessage()) System.out.println System.out System System.out e.getMessage() e.getMessage e return null; null {
                byte[] buf = new byte[10000000]; // line length 
                int cnt = 0, c; 
                while ((c = read()) != -1) { 
                    if (c == '\n') 
                        break; 
                    buf[cnt++] = (byte) c; 
                } 
                return new String(buf, 0, cnt); 
            } byte[] buf = new byte[10000000]; buf new byte[10000000] 10000000 int cnt = 0 cnt 0 c; c while ((c = read()) != -1) { 
                    if (c == '\n') 
                        break; 
                    buf[cnt++] = (byte) c; 
                } (c = read()) != -1 (c = read()) c read() read -1 1 { 
                    if (c == '\n') 
                        break; 
                    buf[cnt++] = (byte) c; 
                } if (c == '\n') 
                        break; c == '\n' c '\n' break; buf[cnt++] = (byte) c buf[cnt++] buf cnt++ cnt (byte) c return new String(buf, 0, cnt); new String(buf, 0, cnt) public int nextInt()  { 
            int ret = 0; 
            try {
                byte c = read(); 
                while (c <= ' ') 
                    c = read(); 
                boolean neg = (c == '-'); 
                if (neg) c = read(); 
                do{ 
                    ret = ret * 10 + c - '0'; 
                }  while ((c = read()) >= '0' && c <= '9'); 
    
                if (neg) return -ret; 
                return ret; 
            } catch (Exception e) {
                System.out.println(e.getMessage());
                return -1;
            }
        } nextInt { 
            int ret = 0; 
            try {
                byte c = read(); 
                while (c <= ' ') 
                    c = read(); 
                boolean neg = (c == '-'); 
                if (neg) c = read(); 
                do{ 
                    ret = ret * 10 + c - '0'; 
                }  while ((c = read()) >= '0' && c <= '9'); 
    
                if (neg) return -ret; 
                return ret; 
            } catch (Exception e) {
                System.out.println(e.getMessage());
                return -1;
            }
        } int ret = 0; ret 0 try {
                byte c = read(); 
                while (c <= ' ') 
                    c = read(); 
                boolean neg = (c == '-'); 
                if (neg) c = read(); 
                do{ 
                    ret = ret * 10 + c - '0'; 
                }  while ((c = read()) >= '0' && c <= '9'); 
    
                if (neg) return -ret; 
                return ret; 
            } catch (Exception e) {
                System.out.println(e.getMessage());
                return -1;
            } catch (Exception e) {
                System.out.println(e.getMessage());
                return -1;
            } Exception e {
                System.out.println(e.getMessage());
                return -1;
            } System.out.println(e.getMessage()) System.out.println System.out System System.out e.getMessage() e.getMessage e return -1; -1 1 {
                byte c = read(); 
                while (c <= ' ') 
                    c = read(); 
                boolean neg = (c == '-'); 
                if (neg) c = read(); 
                do{ 
                    ret = ret * 10 + c - '0'; 
                }  while ((c = read()) >= '0' && c <= '9'); 
    
                if (neg) return -ret; 
                return ret; 
            } byte c = read(); c read() read while (c <= ' ') 
                    c = read(); c <= ' ' c ' ' c = read() c read() read boolean neg = (c == '-'); neg (c == '-') c '-' if (neg) c = read(); neg c = read() c read() read do{ 
                    ret = ret * 10 + c - '0'; 
                }  while ((c = read()) >= '0' && c <= '9'); (c = read()) >= '0' && c <= '9' (c = read()) >= '0' (c = read()) c read() read '0' c <= '9' c '9' { 
                    ret = ret * 10 + c - '0'; 
                } ret = ret * 10 + c - '0' ret ret * 10 + c - '0' ret * 10 + c ret * 10 ret 10 c '0' if (neg) return -ret; neg return -ret; -ret ret return ret; ret public long nextLong()   { 
            
            try {
                long ret = 0; 
                byte c = read(); 
                while (c <= ' ') c = read(); 
                boolean neg = (c == '-'); 
                if (neg) 
                    c = read(); 
                do { 
                    ret = ret * 10 + c - '0'; 
                } 
                while ((c = read()) >= '0' && c <= '9'); 
                if (neg) 
                    return -ret; 
                return ret;
            } catch (Exception e) {
                System.out.println(e.getMessage());
                return -1;
            }
        } nextLong { 
            
            try {
                long ret = 0; 
                byte c = read(); 
                while (c <= ' ') c = read(); 
                boolean neg = (c == '-'); 
                if (neg) 
                    c = read(); 
                do { 
                    ret = ret * 10 + c - '0'; 
                } 
                while ((c = read()) >= '0' && c <= '9'); 
                if (neg) 
                    return -ret; 
                return ret;
            } catch (Exception e) {
                System.out.println(e.getMessage());
                return -1;
            }
        } try {
                long ret = 0; 
                byte c = read(); 
                while (c <= ' ') c = read(); 
                boolean neg = (c == '-'); 
                if (neg) 
                    c = read(); 
                do { 
                    ret = ret * 10 + c - '0'; 
                } 
                while ((c = read()) >= '0' && c <= '9'); 
                if (neg) 
                    return -ret; 
                return ret;
            } catch (Exception e) {
                System.out.println(e.getMessage());
                return -1;
            } catch (Exception e) {
                System.out.println(e.getMessage());
                return -1;
            } Exception e {
                System.out.println(e.getMessage());
                return -1;
            } System.out.println(e.getMessage()) System.out.println System.out System System.out e.getMessage() e.getMessage e return -1; -1 1 {
                long ret = 0; 
                byte c = read(); 
                while (c <= ' ') c = read(); 
                boolean neg = (c == '-'); 
                if (neg) 
                    c = read(); 
                do { 
                    ret = ret * 10 + c - '0'; 
                } 
                while ((c = read()) >= '0' && c <= '9'); 
                if (neg) 
                    return -ret; 
                return ret;
            } long ret = 0; ret 0 byte c = read(); c read() read while (c <= ' ') c = read(); c <= ' ' c ' ' c = read() c read() read boolean neg = (c == '-'); neg (c == '-') c '-' if (neg) 
                    c = read(); neg c = read() c read() read do { 
                    ret = ret * 10 + c - '0'; 
                } 
                while ((c = read()) >= '0' && c <= '9'); (c = read()) >= '0' && c <= '9' (c = read()) >= '0' (c = read()) c read() read '0' c <= '9' c '9' { 
                    ret = ret * 10 + c - '0'; 
                } ret = ret * 10 + c - '0' ret ret * 10 + c - '0' ret * 10 + c ret * 10 ret 10 c '0' if (neg) 
                    return -ret; neg return -ret; -ret ret return ret; ret public double nextDouble()  { 
            
            try {
                double ret = 0, div = 1; 
                byte c = read(); 
                while (c <= ' ') 
                    c = read(); 
                boolean neg = (c == '-'); 
                if (neg) c = read(); 
    
                do { 
                    ret = ret * 10 + c - '0'; 
                } 
                while ((c = read()) >= '0' && c <= '9'); 
                if (c == '.') { 
                    while ((c = read()) >= '0' && c <= '9') { 
                        ret += (c - '0') / (div *= 10); 
                    } 
                } 
    
                if (neg) return -ret; 
                return ret;
            } catch (Exception e) {
                System.out.println(e.getMessage());
                return -1;
            }
        } nextDouble { 
            
            try {
                double ret = 0, div = 1; 
                byte c = read(); 
                while (c <= ' ') 
                    c = read(); 
                boolean neg = (c == '-'); 
                if (neg) c = read(); 
    
                do { 
                    ret = ret * 10 + c - '0'; 
                } 
                while ((c = read()) >= '0' && c <= '9'); 
                if (c == '.') { 
                    while ((c = read()) >= '0' && c <= '9') { 
                        ret += (c - '0') / (div *= 10); 
                    } 
                } 
    
                if (neg) return -ret; 
                return ret;
            } catch (Exception e) {
                System.out.println(e.getMessage());
                return -1;
            }
        } try {
                double ret = 0, div = 1; 
                byte c = read(); 
                while (c <= ' ') 
                    c = read(); 
                boolean neg = (c == '-'); 
                if (neg) c = read(); 
    
                do { 
                    ret = ret * 10 + c - '0'; 
                } 
                while ((c = read()) >= '0' && c <= '9'); 
                if (c == '.') { 
                    while ((c = read()) >= '0' && c <= '9') { 
                        ret += (c - '0') / (div *= 10); 
                    } 
                } 
    
                if (neg) return -ret; 
                return ret;
            } catch (Exception e) {
                System.out.println(e.getMessage());
                return -1;
            } catch (Exception e) {
                System.out.println(e.getMessage());
                return -1;
            } Exception e {
                System.out.println(e.getMessage());
                return -1;
            } System.out.println(e.getMessage()) System.out.println System.out System System.out e.getMessage() e.getMessage e return -1; -1 1 {
                double ret = 0, div = 1; 
                byte c = read(); 
                while (c <= ' ') 
                    c = read(); 
                boolean neg = (c == '-'); 
                if (neg) c = read(); 
    
                do { 
                    ret = ret * 10 + c - '0'; 
                } 
                while ((c = read()) >= '0' && c <= '9'); 
                if (c == '.') { 
                    while ((c = read()) >= '0' && c <= '9') { 
                        ret += (c - '0') / (div *= 10); 
                    } 
                } 
    
                if (neg) return -ret; 
                return ret;
            } double ret = 0 ret 0 div = 1; div 1 byte c = read(); c read() read while (c <= ' ') 
                    c = read(); c <= ' ' c ' ' c = read() c read() read boolean neg = (c == '-'); neg (c == '-') c '-' if (neg) c = read(); neg c = read() c read() read do { 
                    ret = ret * 10 + c - '0'; 
                } 
                while ((c = read()) >= '0' && c <= '9'); (c = read()) >= '0' && c <= '9' (c = read()) >= '0' (c = read()) c read() read '0' c <= '9' c '9' { 
                    ret = ret * 10 + c - '0'; 
                } ret = ret * 10 + c - '0' ret ret * 10 + c - '0' ret * 10 + c ret * 10 ret 10 c '0' if (c == '.') { 
                    while ((c = read()) >= '0' && c <= '9') { 
                        ret += (c - '0') / (div *= 10); 
                    } 
                } c == '.' c '.' { 
                    while ((c = read()) >= '0' && c <= '9') { 
                        ret += (c - '0') / (div *= 10); 
                    } 
                } while ((c = read()) >= '0' && c <= '9') { 
                        ret += (c - '0') / (div *= 10); 
                    } (c = read()) >= '0' && c <= '9' (c = read()) >= '0' (c = read()) c read() read '0' c <= '9' c '9' { 
                        ret += (c - '0') / (div *= 10); 
                    } ret += (c - '0') / (div *= 10) ret (c - '0') / (div *= 10) (c - '0') c '0' (div *= 10) div 10 if (neg) return -ret; neg return -ret; -ret ret return ret; ret private void fillBuffer() throws IOException{ 
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); 
            if (bytesRead == -1) 
                buffer[0] = -1; 
        } fillBuffer { 
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); 
            if (bytesRead == -1) 
                buffer[0] = -1; 
        } bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE) bytesRead din.read(buffer, bufferPointer = 0, BUFFER_SIZE) din.read din buffer bufferPointer = 0 bufferPointer 0 BUFFER_SIZE if (bytesRead == -1) 
                buffer[0] = -1; bytesRead == -1 bytesRead -1 1 buffer[0] = -1 buffer[0] buffer 0 -1 1 private byte read() throws IOException  { 
            try{
                if (bufferPointer == bytesRead) 
                    fillBuffer(); 
                return buffer[bufferPointer++]; 
            }catch(Exception e){
                System.out.println(e.getMessage());
                return -1;
            }
        } read { 
            try{
                if (bufferPointer == bytesRead) 
                    fillBuffer(); 
                return buffer[bufferPointer++]; 
            }catch(Exception e){
                System.out.println(e.getMessage());
                return -1;
            }
        } try{
                if (bufferPointer == bytesRead) 
                    fillBuffer(); 
                return buffer[bufferPointer++]; 
            }catch(Exception e){
                System.out.println(e.getMessage());
                return -1;
            } catch(Exception e){
                System.out.println(e.getMessage());
                return -1;
            } Exception e {
                System.out.println(e.getMessage());
                return -1;
            } System.out.println(e.getMessage()) System.out.println System.out System System.out e.getMessage() e.getMessage e return -1; -1 1 {
                if (bufferPointer == bytesRead) 
                    fillBuffer(); 
                return buffer[bufferPointer++]; 
            } if (bufferPointer == bytesRead) 
                    fillBuffer(); bufferPointer == bytesRead bufferPointer bytesRead fillBuffer() fillBuffer return buffer[bufferPointer++]; buffer[bufferPointer++] buffer bufferPointer++ bufferPointer public void close() throws IOException { 
            if (din == null) 
                return; 
            din.close(); 
        } close { 
            if (din == null) 
                return; 
            din.close(); 
        } if (din == null) 
                return; din == null din null return; din.close() din.close din public class Main{
        public static void main(String args[]){
            Solver s=new Solver();
            s.run();
        }
    } public class Main{
        public static void main(String args[]){
            Solver s=new Solver();
            s.run();
        }
    } Main
import java.io.*;
import java.util.*;


class Solver {            
    StringBuilder out=new StringBuilder(100);
    FastReader in=new FastReader();
    public long pow(long a, long b){
        if(b==0)return 1;
            long ans=pow(a,b/2);
            ans*=ans;
            ans%=mod;
        if(b%2==1){
            ans*=a;
            ans%=mod;
        }
        return ans;
    }
    
    public int[] getIntArray(int n){
        int arr[]=new int[n];
        for(int i=0;i<n;i++){
            arr[i]=in.nextInt();
        }
        return arr;
    }

    int  mod=(int)(1e9 + 7);
    
    public void solve(){
        int n=in.nextInt(),k=in.nextInt();
        int arr[]=getIntArray(n);
        int dp[]=new int[n+1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0]=0;
        for(int i=0;i<n;i++){
            for(int j=1;j<=k && i+j<n;j++){
                dp[i+j]=Math.min(dp[i+j], dp[i]+Math.abs(arr[i]-arr[i+j]));
            }
        }
        out.append(dp[n-1]);
    }
    public void run(){
        int t=1;
        for(int i=0;i<t;i++){
            solve();
            out.append('\n');
        }
        System.out.println(out);
    }
}
    
    
    
    
    
/////////////////////
    
    
    
    
    
    
    public class Main{
        public static void main(String args[]){
            Solver s=new Solver();
            s.run();
        }
    } 
    
    class FastReader { 
        final private int BUFFER_SIZE = 1 << 16; 
        private DataInputStream din; 
        private byte[] buffer; 
        private int bufferPointer, bytesRead; 
    
        public FastReader() { 
            din = new DataInputStream(System.in); 
            buffer = new byte[BUFFER_SIZE]; 
            bufferPointer = bytesRead = 0; 
        } 
    
        public FastReader(String file_name) throws IOException{ 
            din = new DataInputStream(new FileInputStream(file_name)); 
            buffer = new byte[BUFFER_SIZE]; 
            bufferPointer = bytesRead = 0; 
        } 
    
        public String nextLine() { 
            try{
                byte[] buf = new byte[10000000]; // line length 
                int cnt = 0, c; 
                while ((c = read()) != -1) { 
                    if (c == '\n') 
                        break; 
                    buf[cnt++] = (byte) c; 
                } 
                return new String(buf, 0, cnt); 
            }catch (Exception e){
                System.out.println(e.getMessage());
                return null;
            }
        } 
    
        public int nextInt()  { 
            int ret = 0; 
            try {
                byte c = read(); 
                while (c <= ' ') 
                    c = read(); 
                boolean neg = (c == '-'); 
                if (neg) c = read(); 
                do{ 
                    ret = ret * 10 + c - '0'; 
                }  while ((c = read()) >= '0' && c <= '9'); 
    
                if (neg) return -ret; 
                return ret; 
            } catch (Exception e) {
                System.out.println(e.getMessage());
                return -1;
            }
        } 
    
        public long nextLong()   { 
            
            try {
                long ret = 0; 
                byte c = read(); 
                while (c <= ' ') c = read(); 
                boolean neg = (c == '-'); 
                if (neg) 
                    c = read(); 
                do { 
                    ret = ret * 10 + c - '0'; 
                } 
                while ((c = read()) >= '0' && c <= '9'); 
                if (neg) 
                    return -ret; 
                return ret;
            } catch (Exception e) {
                System.out.println(e.getMessage());
                return -1;
            }
        } 
    
        public double nextDouble()  { 
            
            try {
                double ret = 0, div = 1; 
                byte c = read(); 
                while (c <= ' ') 
                    c = read(); 
                boolean neg = (c == '-'); 
                if (neg) c = read(); 
    
                do { 
                    ret = ret * 10 + c - '0'; 
                } 
                while ((c = read()) >= '0' && c <= '9'); 
                if (c == '.') { 
                    while ((c = read()) >= '0' && c <= '9') { 
                        ret += (c - '0') / (div *= 10); 
                    } 
                } 
    
                if (neg) return -ret; 
                return ret;
            } catch (Exception e) {
                System.out.println(e.getMessage());
                return -1;
            }
        } 
    
        private void fillBuffer() throws IOException{ 
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); 
            if (bytesRead == -1) 
                buffer[0] = -1; 
        } 
    
        private byte read() throws IOException  { 
            try{
                if (bufferPointer == bytesRead) 
                    fillBuffer(); 
                return buffer[bufferPointer++]; 
            }catch(Exception e){
                System.out.println(e.getMessage());
                return -1;
            }
        } 
    
        public void close() throws IOException { 
            if (din == null) 
                return; 
            din.close(); 
        } 
    } 


    // class FastReader {
    //     BufferedReader br;
    //     StringTokenizer st;
    
    //     public FastReader() {
    //         br = new BufferedReader(new InputStreamReader(System.in));
    //     }
    
    //     String next() {
    //         while (st == null || !st.hasMoreElements()) {
    //             try {
    //                 st = new StringTokenizer(br.readLine());
    //             } catch (IOException e) {
    //                 e.printStackTrace();
    //             }
    //         }
    //         return st.nextToken();
    //     }
    
    //     int nextInt() {
    //         return Integer.parseInt(next());
    //     }
    
    //     long nextLong() {
    //         return Long.parseLong(next());
    //     }
    
    //     double nextDouble() {
    //         return Double.parseDouble(next());
    //     }
    
    //     String nextLine() {
    //         String str = "";
    //         try {
    //             str = br.readLine();
    //         } catch (IOException e) {
    //             e.printStackTrace();
    //         }
    //         return str;
    //     }
    // }