/*
    Author: Anthony Ngene
    Created: 09/08/2020 - 22:40
*/

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

public class Main {
    // That which does not kill us makes us stronger. - Friedrich Nietzsche
    public static void main(String[] args) throws IOException {
        in = new FastScanner();

        int n = in.intNext();
        long k = in.longNext();
        long[] arr = in.nextLongArray(n);
        long[] dp = new long[n];
        Arrays.fill(dp, e97);
        dp[0] = 0;
        for (int i = 1; i < n; i++) {
            for (int j = 1; j < k + 1; j++)
                if (i - j >= 0) dp[i] = min(dp[i], abs(dp[i - j] + abs(arr[i] - arr[i - j])));
        }
        out.println(dp[n - 1]);

        out.close();
    }


    // Generated Code Below:
    private static final FastWriter out = new FastWriter();
    private static FastScanner in;
    static ArrayList<Integer>[] adj;
    private static long e97 = (long)1e9 + 7;
    static class FastWriter {
        private static final int IO_BUFFERS = 128 * 1024;
        private final StringBuilder out;
        public FastWriter() { out = new StringBuilder(IO_BUFFERS); }
        public FastWriter p(Object object) { out.append(object); return this; }
        public FastWriter p(String format, Object... args) { out.append(String.format(format, args)); return this; }
        public FastWriter pp(Object... args) { for (Object ob : args) { out.append(ob).append(" ");  } out.append("\n"); return this; }
        public void println(long[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public void println(int[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public void println(char[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public void println(float[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public void println(boolean[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public <T>void println(T[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public void println(long[][] arr) {  for (long[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  }
        public void println(int[][] arr) {  for (int[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  }
        public void println(char[][] arr) {  for (char[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  }
        public void println(float[][] arr) {  for (float[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  }
        public <T>void println(T[][] arr) {  for (T[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  }
        public FastWriter println(Object object) { out.append(object).append("\n"); return this; }
        public void toFile(String fileName) throws IOException {
            BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
            writer.write(out.toString());
            writer.close();
        }
        public void close() throws IOException { System.out.print(out); }
    }
    static class FastScanner {
        private InputStream sin = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        public FastScanner(){}
        public FastScanner(String filename) throws FileNotFoundException {
            File file = new File(filename);
            sin = new FileInputStream(file);
        }
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            }else{
                ptr = 0;
                try {
                    buflen = sin.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long longNext() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b) || b == ':'){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
        public int intNext() {
            long nl = longNext();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double doubleNext() { return Double.parseDouble(next());}
        public long[] nextLongArray(final int n){
            final long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = longNext();
            return a;
        }
        public int[] nextIntArray(final int n){
            final int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = intNext();
            return a;
        }
        public ArrayList<Integer>[] getAdj(int n) {
            ArrayList<Integer>[] adj = new ArrayList[n + 1];
            for (int i = 1; i <= n; i++) adj[i] = new ArrayList<>();
            return adj;
        }
        public ArrayList<Integer>[] adjacencyList(int n, int m) throws IOException {
            adj = getAdj(n);
            for (int i = 0; i < m; i++) {
                int a = intNext(), b = intNext();
                adj[a].add(b);
                adj[b].add(a);
            }
            return adj;
        }
    }
    private static long abs(long a){    return (a>=0) ? a: -a;  }
    private static long min(long... ins){ long min = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] < min) min = ins[i]; } return min; }
} import java.io.*; io.* java import java.util.*; util.* java public class Main {
    // That which does not kill us makes us stronger. - Friedrich Nietzsche
    public static void main(String[] args) throws IOException {
        in = new FastScanner();

        int n = in.intNext();
        long k = in.longNext();
        long[] arr = in.nextLongArray(n);
        long[] dp = new long[n];
        Arrays.fill(dp, e97);
        dp[0] = 0;
        for (int i = 1; i < n; i++) {
            for (int j = 1; j < k + 1; j++)
                if (i - j >= 0) dp[i] = min(dp[i], abs(dp[i - j] + abs(arr[i] - arr[i - j])));
        }
        out.println(dp[n - 1]);

        out.close();
    }


    // Generated Code Below:
    private static final FastWriter out = new FastWriter();
    private static FastScanner in;
    static ArrayList<Integer>[] adj;
    private static long e97 = (long)1e9 + 7;
    static class FastWriter {
        private static final int IO_BUFFERS = 128 * 1024;
        private final StringBuilder out;
        public FastWriter() { out = new StringBuilder(IO_BUFFERS); }
        public FastWriter p(Object object) { out.append(object); return this; }
        public FastWriter p(String format, Object... args) { out.append(String.format(format, args)); return this; }
        public FastWriter pp(Object... args) { for (Object ob : args) { out.append(ob).append(" ");  } out.append("\n"); return this; }
        public void println(long[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public void println(int[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public void println(char[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public void println(float[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public void println(boolean[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public <T>void println(T[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public void println(long[][] arr) {  for (long[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  }
        public void println(int[][] arr) {  for (int[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  }
        public void println(char[][] arr) {  for (char[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  }
        public void println(float[][] arr) {  for (float[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  }
        public <T>void println(T[][] arr) {  for (T[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  }
        public FastWriter println(Object object) { out.append(object).append("\n"); return this; }
        public void toFile(String fileName) throws IOException {
            BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
            writer.write(out.toString());
            writer.close();
        }
        public void close() throws IOException { System.out.print(out); }
    }
    static class FastScanner {
        private InputStream sin = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        public FastScanner(){}
        public FastScanner(String filename) throws FileNotFoundException {
            File file = new File(filename);
            sin = new FileInputStream(file);
        }
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            }else{
                ptr = 0;
                try {
                    buflen = sin.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long longNext() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b) || b == ':'){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
        public int intNext() {
            long nl = longNext();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double doubleNext() { return Double.parseDouble(next());}
        public long[] nextLongArray(final int n){
            final long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = longNext();
            return a;
        }
        public int[] nextIntArray(final int n){
            final int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = intNext();
            return a;
        }
        public ArrayList<Integer>[] getAdj(int n) {
            ArrayList<Integer>[] adj = new ArrayList[n + 1];
            for (int i = 1; i <= n; i++) adj[i] = new ArrayList<>();
            return adj;
        }
        public ArrayList<Integer>[] adjacencyList(int n, int m) throws IOException {
            adj = getAdj(n);
            for (int i = 0; i < m; i++) {
                int a = intNext(), b = intNext();
                adj[a].add(b);
                adj[b].add(a);
            }
            return adj;
        }
    }
    private static long abs(long a){    return (a>=0) ? a: -a;  }
    private static long min(long... ins){ long min = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] < min) min = ins[i]; } return min; }
} Main // Generated Code Below:
    private static final FastWriter out = new FastWriter(); out new FastWriter() private static FastScanner in; in static ArrayList<Integer>[] adj; adj private static long e97 = (long)1e9 + 7; e97 (long)1e9 + 7 (long)1e9 7 // That which does not kill us makes us stronger. - Friedrich Nietzsche
    public static void main(String[] args) throws IOException {
        in = new FastScanner();

        int n = in.intNext();
        long k = in.longNext();
        long[] arr = in.nextLongArray(n);
        long[] dp = new long[n];
        Arrays.fill(dp, e97);
        dp[0] = 0;
        for (int i = 1; i < n; i++) {
            for (int j = 1; j < k + 1; j++)
                if (i - j >= 0) dp[i] = min(dp[i], abs(dp[i - j] + abs(arr[i] - arr[i - j])));
        }
        out.println(dp[n - 1]);

        out.close();
    } main {
        in = new FastScanner();

        int n = in.intNext();
        long k = in.longNext();
        long[] arr = in.nextLongArray(n);
        long[] dp = new long[n];
        Arrays.fill(dp, e97);
        dp[0] = 0;
        for (int i = 1; i < n; i++) {
            for (int j = 1; j < k + 1; j++)
                if (i - j >= 0) dp[i] = min(dp[i], abs(dp[i - j] + abs(arr[i] - arr[i - j])));
        }
        out.println(dp[n - 1]);

        out.close();
    } in = new FastScanner() in new FastScanner() int n = in.intNext(); n in.intNext() in.intNext in long k = in.longNext(); k in.longNext() in.longNext in long[] arr = in.nextLongArray(n); arr in.nextLongArray(n) in.nextLongArray in n long[] dp = new long[n]; dp new long[n] n Arrays.fill(dp, e97) Arrays.fill Arrays dp e97 dp[0] = 0 dp[0] dp 0 0 for (int i = 1; i < n; i++) {
            for (int j = 1; j < k + 1; j++)
                if (i - j >= 0) dp[i] = min(dp[i], abs(dp[i - j] + abs(arr[i] - arr[i - j])));
        } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
            for (int j = 1; j < k + 1; j++)
                if (i - j >= 0) dp[i] = min(dp[i], abs(dp[i - j] + abs(arr[i] - arr[i - j])));
        } {
            for (int j = 1; j < k + 1; j++)
                if (i - j >= 0) dp[i] = min(dp[i], abs(dp[i - j] + abs(arr[i] - arr[i - j])));
        } for (int j = 1; j < k + 1; j++)
                if (i - j >= 0) dp[i] = min(dp[i], abs(dp[i - j] + abs(arr[i] - arr[i - j]))); int j = 1; int j = 1; j 1 j < k + 1 j k + 1 k 1 j++ j++ j if (i - j >= 0) dp[i] = min(dp[i], abs(dp[i - j] + abs(arr[i] - arr[i - j]))); if (i - j >= 0) dp[i] = min(dp[i], abs(dp[i - j] + abs(arr[i] - arr[i - j]))); i - j >= 0 i - j i j 0 dp[i] = min(dp[i], abs(dp[i - j] + abs(arr[i] - arr[i - j]))) dp[i] dp i min(dp[i], abs(dp[i - j] + abs(arr[i] - arr[i - j]))) min dp[i] dp i abs(dp[i - j] + abs(arr[i] - arr[i - j])) abs dp[i - j] + abs(arr[i] - arr[i - j]) dp[i - j] dp i - j i j abs(arr[i] - arr[i - j]) abs arr[i] - arr[i - j] arr[i] arr i arr[i - j] arr i - j i j out.println(dp[n - 1]) out.println out dp[n - 1] dp n - 1 n 1 out.close() out.close out String[] args args private static long abs(long a){    return (a>=0) ? a: -a;  } abs {    return (a>=0) ? a: -a;  } return (a>=0) ? a: -a; (a>=0) ? a: -a (a>=0) a 0 a -a a long a a private static long min(long... ins){ long min = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] < min) min = ins[i]; } return min; } min { long min = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] < min) min = ins[i]; } return min; } long min = ins[0]; min ins[0] ins 0 for(int i=1; i<ins.length; i++){ if(ins[i] < min) min = ins[i]; } int i=1; int i=1; i 1 i<ins.length i ins.length ins ins.length i++ i++ i { if(ins[i] < min) min = ins[i]; } { if(ins[i] < min) min = ins[i]; } if(ins[i] < min) min = ins[i]; ins[i] < min ins[i] ins i min min = ins[i] min ins[i] ins i return min; min long... ins ins static class FastWriter {
        private static final int IO_BUFFERS = 128 * 1024;
        private final StringBuilder out;
        public FastWriter() { out = new StringBuilder(IO_BUFFERS); }
        public FastWriter p(Object object) { out.append(object); return this; }
        public FastWriter p(String format, Object... args) { out.append(String.format(format, args)); return this; }
        public FastWriter pp(Object... args) { for (Object ob : args) { out.append(ob).append(" ");  } out.append("\n"); return this; }
        public void println(long[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public void println(int[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public void println(char[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public void println(float[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public void println(boolean[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public <T>void println(T[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public void println(long[][] arr) {  for (long[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  }
        public void println(int[][] arr) {  for (int[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  }
        public void println(char[][] arr) {  for (char[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  }
        public void println(float[][] arr) {  for (float[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  }
        public <T>void println(T[][] arr) {  for (T[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  }
        public FastWriter println(Object object) { out.append(object).append("\n"); return this; }
        public void toFile(String fileName) throws IOException {
            BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
            writer.write(out.toString());
            writer.close();
        }
        public void close() throws IOException { System.out.print(out); }
    } FastWriter private static final int IO_BUFFERS = 128 * 1024; IO_BUFFERS 128 * 1024 128 1024 private final StringBuilder out; out public FastWriter() { out = new StringBuilder(IO_BUFFERS); } FastWriter { out = new StringBuilder(IO_BUFFERS); } out = new StringBuilder(IO_BUFFERS) out new StringBuilder(IO_BUFFERS) public FastWriter p(Object object) { out.append(object); return this; } p { out.append(object); return this; } out.append(object) out.append out object return this; this Object object object public FastWriter p(String format, Object... args) { out.append(String.format(format, args)); return this; } p { out.append(String.format(format, args)); return this; } out.append(String.format(format, args)) out.append out String.format(format, args) String.format String format args return this; this String format format Object... args args public FastWriter pp(Object... args) { for (Object ob : args) { out.append(ob).append(" ");  } out.append("\n"); return this; } pp { for (Object ob : args) { out.append(ob).append(" ");  } out.append("\n"); return this; } for (Object ob : args) { out.append(ob).append(" ");  } Object ob args { out.append(ob).append(" ");  } { out.append(ob).append(" ");  } out.append(ob).append(" ") out.append(ob).append out.append(ob) out.append out ob " " out.append("\n") out.append out "\n" return this; this Object... args args public void println(long[] arr) { out.append(Arrays.toString(arr)).append("\n"); } println { out.append(Arrays.toString(arr)).append("\n"); } out.append(Arrays.toString(arr)).append("\n") out.append(Arrays.toString(arr)).append out.append(Arrays.toString(arr)) out.append out Arrays.toString(arr) Arrays.toString Arrays arr "\n" long[] arr arr public void println(int[] arr) { out.append(Arrays.toString(arr)).append("\n"); } println { out.append(Arrays.toString(arr)).append("\n"); } out.append(Arrays.toString(arr)).append("\n") out.append(Arrays.toString(arr)).append out.append(Arrays.toString(arr)) out.append out Arrays.toString(arr) Arrays.toString Arrays arr "\n" int[] arr arr public void println(char[] arr) { out.append(Arrays.toString(arr)).append("\n"); } println { out.append(Arrays.toString(arr)).append("\n"); } out.append(Arrays.toString(arr)).append("\n") out.append(Arrays.toString(arr)).append out.append(Arrays.toString(arr)) out.append out Arrays.toString(arr) Arrays.toString Arrays arr "\n" char[] arr arr public void println(float[] arr) { out.append(Arrays.toString(arr)).append("\n"); } println { out.append(Arrays.toString(arr)).append("\n"); } out.append(Arrays.toString(arr)).append("\n") out.append(Arrays.toString(arr)).append out.append(Arrays.toString(arr)) out.append out Arrays.toString(arr) Arrays.toString Arrays arr "\n" float[] arr arr public void println(boolean[] arr) { out.append(Arrays.toString(arr)).append("\n"); } println { out.append(Arrays.toString(arr)).append("\n"); } out.append(Arrays.toString(arr)).append("\n") out.append(Arrays.toString(arr)).append out.append(Arrays.toString(arr)) out.append out Arrays.toString(arr) Arrays.toString Arrays arr "\n" boolean[] arr arr public <T>void println(T[] arr) { out.append(Arrays.toString(arr)).append("\n"); } println { out.append(Arrays.toString(arr)).append("\n"); } out.append(Arrays.toString(arr)).append("\n") out.append(Arrays.toString(arr)).append out.append(Arrays.toString(arr)) out.append out Arrays.toString(arr) Arrays.toString Arrays arr "\n" T[] arr arr public void println(long[][] arr) {  for (long[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  } println {  for (long[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  } for (long[] row: arr) out.append(Arrays.toString(row)).append(" "); long[] row arr out.append(Arrays.toString(row)).append(" "); out.append(Arrays.toString(row)).append(" ") out.append(Arrays.toString(row)).append out.append(Arrays.toString(row)) out.append out Arrays.toString(row) Arrays.toString Arrays row " " out.append("\n") out.append out "\n" long[][] arr arr public void println(int[][] arr) {  for (int[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  } println {  for (int[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  } for (int[] row: arr) out.append(Arrays.toString(row)).append(" "); int[] row arr out.append(Arrays.toString(row)).append(" "); out.append(Arrays.toString(row)).append(" ") out.append(Arrays.toString(row)).append out.append(Arrays.toString(row)) out.append out Arrays.toString(row) Arrays.toString Arrays row " " out.append("\n") out.append out "\n" int[][] arr arr public void println(char[][] arr) {  for (char[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  } println {  for (char[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  } for (char[] row: arr) out.append(Arrays.toString(row)).append(" "); char[] row arr out.append(Arrays.toString(row)).append(" "); out.append(Arrays.toString(row)).append(" ") out.append(Arrays.toString(row)).append out.append(Arrays.toString(row)) out.append out Arrays.toString(row) Arrays.toString Arrays row " " out.append("\n") out.append out "\n" char[][] arr arr public void println(float[][] arr) {  for (float[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  } println {  for (float[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  } for (float[] row: arr) out.append(Arrays.toString(row)).append(" "); float[] row arr out.append(Arrays.toString(row)).append(" "); out.append(Arrays.toString(row)).append(" ") out.append(Arrays.toString(row)).append out.append(Arrays.toString(row)) out.append out Arrays.toString(row) Arrays.toString Arrays row " " out.append("\n") out.append out "\n" float[][] arr arr public <T>void println(T[][] arr) {  for (T[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  } println {  for (T[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  } for (T[] row: arr) out.append(Arrays.toString(row)).append(" "); T[] row arr out.append(Arrays.toString(row)).append(" "); out.append(Arrays.toString(row)).append(" ") out.append(Arrays.toString(row)).append out.append(Arrays.toString(row)) out.append out Arrays.toString(row) Arrays.toString Arrays row " " out.append("\n") out.append out "\n" T[][] arr arr public FastWriter println(Object object) { out.append(object).append("\n"); return this; } println { out.append(object).append("\n"); return this; } out.append(object).append("\n") out.append(object).append out.append(object) out.append out object "\n" return this; this Object object object public void toFile(String fileName) throws IOException {
            BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
            writer.write(out.toString());
            writer.close();
        } toFile {
            BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
            writer.write(out.toString());
            writer.close();
        } BufferedWriter writer = new BufferedWriter(new FileWriter(fileName)); writer new BufferedWriter(new FileWriter(fileName)) writer.write(out.toString()) writer.write writer out.toString() out.toString out writer.close() writer.close writer String fileName fileName public void close() throws IOException { System.out.print(out); } close { System.out.print(out); } System.out.print(out) System.out.print System.out System System.out out static class FastScanner {
        private InputStream sin = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        public FastScanner(){}
        public FastScanner(String filename) throws FileNotFoundException {
            File file = new File(filename);
            sin = new FileInputStream(file);
        }
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            }else{
                ptr = 0;
                try {
                    buflen = sin.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long longNext() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b) || b == ':'){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
        public int intNext() {
            long nl = longNext();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double doubleNext() { return Double.parseDouble(next());}
        public long[] nextLongArray(final int n){
            final long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = longNext();
            return a;
        }
        public int[] nextIntArray(final int n){
            final int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = intNext();
            return a;
        }
        public ArrayList<Integer>[] getAdj(int n) {
            ArrayList<Integer>[] adj = new ArrayList[n + 1];
            for (int i = 1; i <= n; i++) adj[i] = new ArrayList<>();
            return adj;
        }
        public ArrayList<Integer>[] adjacencyList(int n, int m) throws IOException {
            adj = getAdj(n);
            for (int i = 0; i < m; i++) {
                int a = intNext(), b = intNext();
                adj[a].add(b);
                adj[b].add(a);
            }
            return adj;
        }
    } FastScanner private InputStream sin = System.in; sin System.in System System.in private final byte[] buffer = new byte[1024]; buffer new byte[1024] 1024 private int ptr = 0; ptr 0 private int buflen = 0; buflen 0 public FastScanner(){} FastScanner {} public FastScanner(String filename) throws FileNotFoundException {
            File file = new File(filename);
            sin = new FileInputStream(file);
        } FastScanner {
            File file = new File(filename);
            sin = new FileInputStream(file);
        } File file = new File(filename); file new File(filename) sin = new FileInputStream(file) sin new FileInputStream(file) String filename filename private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            }else{
                ptr = 0;
                try {
                    buflen = sin.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        } hasNextByte {
            if (ptr < buflen) {
                return true;
            }else{
                ptr = 0;
                try {
                    buflen = sin.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        } if (ptr < buflen) {
                return true;
            }else{
                ptr = 0;
                try {
                    buflen = sin.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            } ptr < buflen ptr buflen {
                return true;
            } return true; true {
                ptr = 0;
                try {
                    buflen = sin.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            } ptr = 0 ptr 0 try {
                    buflen = sin.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } IOException e {
                    e.printStackTrace();
                } e.printStackTrace() e.printStackTrace e {
                    buflen = sin.read(buffer);
                } buflen = sin.read(buffer) buflen sin.read(buffer) sin.read sin buffer if (buflen <= 0) {
                    return false;
                } buflen <= 0 buflen 0 {
                    return false;
                } return false; false return true; true private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;} readByte { if (hasNextByte()) return buffer[ptr++]; else return -1;} if (hasNextByte()) return buffer[ptr++]; else return -1; hasNextByte() hasNextByte return buffer[ptr++]; buffer[ptr++] buffer ptr++ ptr return -1; -1 1 private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;} isPrintableChar { return 33 <= c && c <= 126;} return 33 <= c && c <= 126; 33 <= c && c <= 126 33 <= c 33 c c <= 126 c 126 int c c public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();} hasNext { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();} while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; hasNextByte() && !isPrintableChar(buffer[ptr]) hasNextByte() hasNextByte !isPrintableChar(buffer[ptr]) isPrintableChar(buffer[ptr]) isPrintableChar buffer[ptr] buffer ptr ptr++ ptr return hasNextByte(); hasNextByte() hasNextByte public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        } next {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        } if (!hasNext()) throw new NoSuchElementException(); !hasNext() hasNext() hasNext throw new NoSuchElementException(); new NoSuchElementException() StringBuilder sb = new StringBuilder(); sb new StringBuilder() int b = readByte(); b readByte() readByte while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            } isPrintableChar(b) isPrintableChar b {
                sb.appendCodePoint(b);
                b = readByte();
            } sb.appendCodePoint(b) sb.appendCodePoint sb b b = readByte() b readByte() readByte return sb.toString(); sb.toString() sb.toString sb public long longNext() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b) || b == ':'){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        } longNext {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b) || b == ':'){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        } if (!hasNext()) throw new NoSuchElementException(); !hasNext() hasNext() hasNext throw new NoSuchElementException(); new NoSuchElementException() long n = 0; n 0 boolean minus = false; minus false int b = readByte(); b readByte() readByte if (b == '-') {
                minus = true;
                b = readByte();
            } b == '-' b '-' {
                minus = true;
                b = readByte();
            } minus = true minus true b = readByte() b readByte() readByte if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            } b < '0' || '9' < b b < '0' b '0' '9' < b '9' b {
                throw new NumberFormatException();
            } throw new NumberFormatException(); new NumberFormatException() while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b) || b == ':'){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            } true {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b) || b == ':'){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            } if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b) || b == ':'){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                } '0' <= b && b <= '9' '0' <= b '0' b b <= '9' b '9' {
                    n *= 10;
                    n += b - '0';
                } n *= 10 n 10 n += b - '0' n b - '0' b '0' if(b == -1 || !isPrintableChar(b) || b == ':'){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                } b == -1 || !isPrintableChar(b) || b == ':' b == -1 || !isPrintableChar(b) || b == ':' b == -1 b -1 1 !isPrintableChar(b) isPrintableChar(b) isPrintableChar b b == ':' b ':' {
                    return minus ? -n : n;
                } return minus ? -n : n; minus ? -n : n minus -n n n {
                    throw new NumberFormatException();
                } throw new NumberFormatException(); new NumberFormatException() b = readByte() b readByte() readByte public int intNext() {
            long nl = longNext();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        } intNext {
            long nl = longNext();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        } long nl = longNext(); nl longNext() longNext if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException(); nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE nl < Integer.MIN_VALUE nl Integer.MIN_VALUE Integer Integer.MIN_VALUE nl > Integer.MAX_VALUE nl Integer.MAX_VALUE Integer Integer.MAX_VALUE throw new NumberFormatException(); new NumberFormatException() return (int) nl; (int) nl public double doubleNext() { return Double.parseDouble(next());} doubleNext { return Double.parseDouble(next());} return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next public long[] nextLongArray(final int n){
            final long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = longNext();
            return a;
        } nextLongArray {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = longNext();
            return a;
        } final long[] a = new long[n]; a new long[n] n for (int i = 0; i < n; i++)
                a[i] = longNext(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i a[i] = longNext(); a[i] = longNext() a[i] a i longNext() longNext return a; a final int n n public int[] nextIntArray(final int n){
            final int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = intNext();
            return a;
        } nextIntArray {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = intNext();
            return a;
        } final int[] a = new int[n]; a new int[n] n for (int i = 0; i < n; i++)
                a[i] = intNext(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i a[i] = intNext(); a[i] = intNext() a[i] a i intNext() intNext return a; a final int n n public ArrayList<Integer>[] getAdj(int n) {
            ArrayList<Integer>[] adj = new ArrayList[n + 1];
            for (int i = 1; i <= n; i++) adj[i] = new ArrayList<>();
            return adj;
        } getAdj {
            ArrayList<Integer>[] adj = new ArrayList[n + 1];
            for (int i = 1; i <= n; i++) adj[i] = new ArrayList<>();
            return adj;
        } ArrayList<Integer>[] adj = new ArrayList[n + 1]; adj new ArrayList[n + 1] n + 1 n 1 for (int i = 1; i <= n; i++) adj[i] = new ArrayList<>(); int i = 1; int i = 1; i 1 i <= n i n i++ i++ i adj[i] = new ArrayList<>(); adj[i] = new ArrayList<>() adj[i] adj i new ArrayList<>() return adj; adj int n n public ArrayList<Integer>[] adjacencyList(int n, int m) throws IOException {
            adj = getAdj(n);
            for (int i = 0; i < m; i++) {
                int a = intNext(), b = intNext();
                adj[a].add(b);
                adj[b].add(a);
            }
            return adj;
        } adjacencyList {
            adj = getAdj(n);
            for (int i = 0; i < m; i++) {
                int a = intNext(), b = intNext();
                adj[a].add(b);
                adj[b].add(a);
            }
            return adj;
        } adj = getAdj(n) adj getAdj(n) getAdj n for (int i = 0; i < m; i++) {
                int a = intNext(), b = intNext();
                adj[a].add(b);
                adj[b].add(a);
            } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
                int a = intNext(), b = intNext();
                adj[a].add(b);
                adj[b].add(a);
            } {
                int a = intNext(), b = intNext();
                adj[a].add(b);
                adj[b].add(a);
            } int a = intNext() a intNext() intNext b = intNext(); b intNext() intNext adj[a].add(b) adj[a].add adj[a] adj a b adj[b].add(a) adj[b].add adj[b] adj b a return adj; adj int n n int m m public class Main {
    // That which does not kill us makes us stronger. - Friedrich Nietzsche
    public static void main(String[] args) throws IOException {
        in = new FastScanner();

        int n = in.intNext();
        long k = in.longNext();
        long[] arr = in.nextLongArray(n);
        long[] dp = new long[n];
        Arrays.fill(dp, e97);
        dp[0] = 0;
        for (int i = 1; i < n; i++) {
            for (int j = 1; j < k + 1; j++)
                if (i - j >= 0) dp[i] = min(dp[i], abs(dp[i - j] + abs(arr[i] - arr[i - j])));
        }
        out.println(dp[n - 1]);

        out.close();
    }


    // Generated Code Below:
    private static final FastWriter out = new FastWriter();
    private static FastScanner in;
    static ArrayList<Integer>[] adj;
    private static long e97 = (long)1e9 + 7;
    static class FastWriter {
        private static final int IO_BUFFERS = 128 * 1024;
        private final StringBuilder out;
        public FastWriter() { out = new StringBuilder(IO_BUFFERS); }
        public FastWriter p(Object object) { out.append(object); return this; }
        public FastWriter p(String format, Object... args) { out.append(String.format(format, args)); return this; }
        public FastWriter pp(Object... args) { for (Object ob : args) { out.append(ob).append(" ");  } out.append("\n"); return this; }
        public void println(long[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public void println(int[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public void println(char[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public void println(float[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public void println(boolean[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public <T>void println(T[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public void println(long[][] arr) {  for (long[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  }
        public void println(int[][] arr) {  for (int[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  }
        public void println(char[][] arr) {  for (char[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  }
        public void println(float[][] arr) {  for (float[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  }
        public <T>void println(T[][] arr) {  for (T[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  }
        public FastWriter println(Object object) { out.append(object).append("\n"); return this; }
        public void toFile(String fileName) throws IOException {
            BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
            writer.write(out.toString());
            writer.close();
        }
        public void close() throws IOException { System.out.print(out); }
    }
    static class FastScanner {
        private InputStream sin = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        public FastScanner(){}
        public FastScanner(String filename) throws FileNotFoundException {
            File file = new File(filename);
            sin = new FileInputStream(file);
        }
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            }else{
                ptr = 0;
                try {
                    buflen = sin.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long longNext() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b) || b == ':'){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
        public int intNext() {
            long nl = longNext();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double doubleNext() { return Double.parseDouble(next());}
        public long[] nextLongArray(final int n){
            final long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = longNext();
            return a;
        }
        public int[] nextIntArray(final int n){
            final int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = intNext();
            return a;
        }
        public ArrayList<Integer>[] getAdj(int n) {
            ArrayList<Integer>[] adj = new ArrayList[n + 1];
            for (int i = 1; i <= n; i++) adj[i] = new ArrayList<>();
            return adj;
        }
        public ArrayList<Integer>[] adjacencyList(int n, int m) throws IOException {
            adj = getAdj(n);
            for (int i = 0; i < m; i++) {
                int a = intNext(), b = intNext();
                adj[a].add(b);
                adj[b].add(a);
            }
            return adj;
        }
    }
    private static long abs(long a){    return (a>=0) ? a: -a;  }
    private static long min(long... ins){ long min = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] < min) min = ins[i]; } return min; }
} public class Main {
    // That which does not kill us makes us stronger. - Friedrich Nietzsche
    public static void main(String[] args) throws IOException {
        in = new FastScanner();

        int n = in.intNext();
        long k = in.longNext();
        long[] arr = in.nextLongArray(n);
        long[] dp = new long[n];
        Arrays.fill(dp, e97);
        dp[0] = 0;
        for (int i = 1; i < n; i++) {
            for (int j = 1; j < k + 1; j++)
                if (i - j >= 0) dp[i] = min(dp[i], abs(dp[i - j] + abs(arr[i] - arr[i - j])));
        }
        out.println(dp[n - 1]);

        out.close();
    }


    // Generated Code Below:
    private static final FastWriter out = new FastWriter();
    private static FastScanner in;
    static ArrayList<Integer>[] adj;
    private static long e97 = (long)1e9 + 7;
    static class FastWriter {
        private static final int IO_BUFFERS = 128 * 1024;
        private final StringBuilder out;
        public FastWriter() { out = new StringBuilder(IO_BUFFERS); }
        public FastWriter p(Object object) { out.append(object); return this; }
        public FastWriter p(String format, Object... args) { out.append(String.format(format, args)); return this; }
        public FastWriter pp(Object... args) { for (Object ob : args) { out.append(ob).append(" ");  } out.append("\n"); return this; }
        public void println(long[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public void println(int[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public void println(char[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public void println(float[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public void println(boolean[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public <T>void println(T[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public void println(long[][] arr) {  for (long[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  }
        public void println(int[][] arr) {  for (int[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  }
        public void println(char[][] arr) {  for (char[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  }
        public void println(float[][] arr) {  for (float[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  }
        public <T>void println(T[][] arr) {  for (T[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  }
        public FastWriter println(Object object) { out.append(object).append("\n"); return this; }
        public void toFile(String fileName) throws IOException {
            BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
            writer.write(out.toString());
            writer.close();
        }
        public void close() throws IOException { System.out.print(out); }
    }
    static class FastScanner {
        private InputStream sin = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        public FastScanner(){}
        public FastScanner(String filename) throws FileNotFoundException {
            File file = new File(filename);
            sin = new FileInputStream(file);
        }
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            }else{
                ptr = 0;
                try {
                    buflen = sin.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long longNext() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b) || b == ':'){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
        public int intNext() {
            long nl = longNext();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double doubleNext() { return Double.parseDouble(next());}
        public long[] nextLongArray(final int n){
            final long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = longNext();
            return a;
        }
        public int[] nextIntArray(final int n){
            final int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = intNext();
            return a;
        }
        public ArrayList<Integer>[] getAdj(int n) {
            ArrayList<Integer>[] adj = new ArrayList[n + 1];
            for (int i = 1; i <= n; i++) adj[i] = new ArrayList<>();
            return adj;
        }
        public ArrayList<Integer>[] adjacencyList(int n, int m) throws IOException {
            adj = getAdj(n);
            for (int i = 0; i < m; i++) {
                int a = intNext(), b = intNext();
                adj[a].add(b);
                adj[b].add(a);
            }
            return adj;
        }
    }
    private static long abs(long a){    return (a>=0) ? a: -a;  }
    private static long min(long... ins){ long min = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] < min) min = ins[i]; } return min; }
} Main
/*
    Author: Anthony Ngene
    Created: 09/08/2020 - 22:40
*/

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

public class Main {
    // That which does not kill us makes us stronger. - Friedrich Nietzsche
    public static void main(String[] args) throws IOException {
        in = new FastScanner();

        int n = in.intNext();
        long k = in.longNext();
        long[] arr = in.nextLongArray(n);
        long[] dp = new long[n];
        Arrays.fill(dp, e97);
        dp[0] = 0;
        for (int i = 1; i < n; i++) {
            for (int j = 1; j < k + 1; j++)
                if (i - j >= 0) dp[i] = min(dp[i], abs(dp[i - j] + abs(arr[i] - arr[i - j])));
        }
        out.println(dp[n - 1]);

        out.close();
    }


    // Generated Code Below:
    private static final FastWriter out = new FastWriter();
    private static FastScanner in;
    static ArrayList<Integer>[] adj;
    private static long e97 = (long)1e9 + 7;
    static class FastWriter {
        private static final int IO_BUFFERS = 128 * 1024;
        private final StringBuilder out;
        public FastWriter() { out = new StringBuilder(IO_BUFFERS); }
        public FastWriter p(Object object) { out.append(object); return this; }
        public FastWriter p(String format, Object... args) { out.append(String.format(format, args)); return this; }
        public FastWriter pp(Object... args) { for (Object ob : args) { out.append(ob).append(" ");  } out.append("\n"); return this; }
        public void println(long[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public void println(int[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public void println(char[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public void println(float[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public void println(boolean[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public <T>void println(T[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
        public void println(long[][] arr) {  for (long[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  }
        public void println(int[][] arr) {  for (int[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  }
        public void println(char[][] arr) {  for (char[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  }
        public void println(float[][] arr) {  for (float[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  }
        public <T>void println(T[][] arr) {  for (T[] row: arr) out.append(Arrays.toString(row)).append(" "); out.append("\n");  }
        public FastWriter println(Object object) { out.append(object).append("\n"); return this; }
        public void toFile(String fileName) throws IOException {
            BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
            writer.write(out.toString());
            writer.close();
        }
        public void close() throws IOException { System.out.print(out); }
    }
    static class FastScanner {
        private InputStream sin = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        public FastScanner(){}
        public FastScanner(String filename) throws FileNotFoundException {
            File file = new File(filename);
            sin = new FileInputStream(file);
        }
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            }else{
                ptr = 0;
                try {
                    buflen = sin.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long longNext() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b) || b == ':'){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
        public int intNext() {
            long nl = longNext();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double doubleNext() { return Double.parseDouble(next());}
        public long[] nextLongArray(final int n){
            final long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = longNext();
            return a;
        }
        public int[] nextIntArray(final int n){
            final int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = intNext();
            return a;
        }
        public ArrayList<Integer>[] getAdj(int n) {
            ArrayList<Integer>[] adj = new ArrayList[n + 1];
            for (int i = 1; i <= n; i++) adj[i] = new ArrayList<>();
            return adj;
        }
        public ArrayList<Integer>[] adjacencyList(int n, int m) throws IOException {
            adj = getAdj(n);
            for (int i = 0; i < m; i++) {
                int a = intNext(), b = intNext();
                adj[a].add(b);
                adj[b].add(a);
            }
            return adj;
        }
    }
    private static long abs(long a){    return (a>=0) ? a: -a;  }
    private static long min(long... ins){ long min = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] < min) min = ins[i]; } return min; }
}
