import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main{
    static 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()));
        }

        String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }
    }

    public static void main(String[] args) {
        FastReader in = new FastReader();
        int n=in.nextInt();
        int k=in.nextInt();
        int h[]=new int[n];
        for(int i=0;i<n;i++){
            h[i]=in.nextInt();
        }
        int a[]=new int[n];
        if(n>k) {
            a[0] = 0;
            for (int i = 1; i <= k; i++) {
                a[i] = Math.abs(h[i] - h[0]);
            }

            for (int i = k; i < n; i++) {
                int y = i - 1;
                int c = 0;
                int min = Integer.MAX_VALUE;
                while (c < k ) {
                    if (min > a[y] + Math.abs(h[y] - h[i])) {
                        min = a[y] + Math.abs(h[y] - h[i]);

                    }
                    y--;
                    c++;
                }
               // System.out.println(min);
                a[i] = min;
            }

            System.out.println(a[n - 1]);
        }
        else{
            System.out.println(h[n-1]-h[0]);
        }

    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.StringTokenizer; StringTokenizer java.util class Main{
    static 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()));
        }

        String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }
    }

    public static void main(String[] args) {
        FastReader in = new FastReader();
        int n=in.nextInt();
        int k=in.nextInt();
        int h[]=new int[n];
        for(int i=0;i<n;i++){
            h[i]=in.nextInt();
        }
        int a[]=new int[n];
        if(n>k) {
            a[0] = 0;
            for (int i = 1; i <= k; i++) {
                a[i] = Math.abs(h[i] - h[0]);
            }

            for (int i = k; i < n; i++) {
                int y = i - 1;
                int c = 0;
                int min = Integer.MAX_VALUE;
                while (c < k ) {
                    if (min > a[y] + Math.abs(h[y] - h[i])) {
                        min = a[y] + Math.abs(h[y] - h[i]);

                    }
                    y--;
                    c++;
                }
               // System.out.println(min);
                a[i] = min;
            }

            System.out.println(a[n - 1]);
        }
        else{
            System.out.println(h[n-1]-h[0]);
        }

    }
} Main public static void main(String[] args) {
        FastReader in = new FastReader();
        int n=in.nextInt();
        int k=in.nextInt();
        int h[]=new int[n];
        for(int i=0;i<n;i++){
            h[i]=in.nextInt();
        }
        int a[]=new int[n];
        if(n>k) {
            a[0] = 0;
            for (int i = 1; i <= k; i++) {
                a[i] = Math.abs(h[i] - h[0]);
            }

            for (int i = k; i < n; i++) {
                int y = i - 1;
                int c = 0;
                int min = Integer.MAX_VALUE;
                while (c < k ) {
                    if (min > a[y] + Math.abs(h[y] - h[i])) {
                        min = a[y] + Math.abs(h[y] - h[i]);

                    }
                    y--;
                    c++;
                }
               // System.out.println(min);
                a[i] = min;
            }

            System.out.println(a[n - 1]);
        }
        else{
            System.out.println(h[n-1]-h[0]);
        }

    } main {
        FastReader in = new FastReader();
        int n=in.nextInt();
        int k=in.nextInt();
        int h[]=new int[n];
        for(int i=0;i<n;i++){
            h[i]=in.nextInt();
        }
        int a[]=new int[n];
        if(n>k) {
            a[0] = 0;
            for (int i = 1; i <= k; i++) {
                a[i] = Math.abs(h[i] - h[0]);
            }

            for (int i = k; i < n; i++) {
                int y = i - 1;
                int c = 0;
                int min = Integer.MAX_VALUE;
                while (c < k ) {
                    if (min > a[y] + Math.abs(h[y] - h[i])) {
                        min = a[y] + Math.abs(h[y] - h[i]);

                    }
                    y--;
                    c++;
                }
               // System.out.println(min);
                a[i] = min;
            }

            System.out.println(a[n - 1]);
        }
        else{
            System.out.println(h[n-1]-h[0]);
        }

    } FastReader in = new FastReader(); in new FastReader() int n=in.nextInt(); n in.nextInt() in.nextInt in int k=in.nextInt(); k in.nextInt() in.nextInt in int h[]=new int[n]; h new int[n] n for(int i=0;i<n;i++){
            h[i]=in.nextInt();
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            h[i]=in.nextInt();
        } {
            h[i]=in.nextInt();
        } h[i]=in.nextInt() h[i] h i in.nextInt() in.nextInt in int a[]=new int[n]; a new int[n] n if(n>k) {
            a[0] = 0;
            for (int i = 1; i <= k; i++) {
                a[i] = Math.abs(h[i] - h[0]);
            }

            for (int i = k; i < n; i++) {
                int y = i - 1;
                int c = 0;
                int min = Integer.MAX_VALUE;
                while (c < k ) {
                    if (min > a[y] + Math.abs(h[y] - h[i])) {
                        min = a[y] + Math.abs(h[y] - h[i]);

                    }
                    y--;
                    c++;
                }
               // System.out.println(min);
                a[i] = min;
            }

            System.out.println(a[n - 1]);
        }
        else{
            System.out.println(h[n-1]-h[0]);
        } n>k n k {
            a[0] = 0;
            for (int i = 1; i <= k; i++) {
                a[i] = Math.abs(h[i] - h[0]);
            }

            for (int i = k; i < n; i++) {
                int y = i - 1;
                int c = 0;
                int min = Integer.MAX_VALUE;
                while (c < k ) {
                    if (min > a[y] + Math.abs(h[y] - h[i])) {
                        min = a[y] + Math.abs(h[y] - h[i]);

                    }
                    y--;
                    c++;
                }
               // System.out.println(min);
                a[i] = min;
            }

            System.out.println(a[n - 1]);
        } a[0] = 0 a[0] a 0 0 for (int i = 1; i <= k; i++) {
                a[i] = Math.abs(h[i] - h[0]);
            } int i = 1; int i = 1; i 1 i <= k i k i++ i++ i {
                a[i] = Math.abs(h[i] - h[0]);
            } {
                a[i] = Math.abs(h[i] - h[0]);
            } a[i] = Math.abs(h[i] - h[0]) a[i] a i Math.abs(h[i] - h[0]) Math.abs Math h[i] - h[0] h[i] h i h[0] h 0 for (int i = k; i < n; i++) {
                int y = i - 1;
                int c = 0;
                int min = Integer.MAX_VALUE;
                while (c < k ) {
                    if (min > a[y] + Math.abs(h[y] - h[i])) {
                        min = a[y] + Math.abs(h[y] - h[i]);

                    }
                    y--;
                    c++;
                }
               // System.out.println(min);
                a[i] = min;
            } int i = k; int i = k; i k i < n i n i++ i++ i {
                int y = i - 1;
                int c = 0;
                int min = Integer.MAX_VALUE;
                while (c < k ) {
                    if (min > a[y] + Math.abs(h[y] - h[i])) {
                        min = a[y] + Math.abs(h[y] - h[i]);

                    }
                    y--;
                    c++;
                }
               // System.out.println(min);
                a[i] = min;
            } {
                int y = i - 1;
                int c = 0;
                int min = Integer.MAX_VALUE;
                while (c < k ) {
                    if (min > a[y] + Math.abs(h[y] - h[i])) {
                        min = a[y] + Math.abs(h[y] - h[i]);

                    }
                    y--;
                    c++;
                }
               // System.out.println(min);
                a[i] = min;
            } int y = i - 1; y i - 1 i 1 int c = 0; c 0 int min = Integer.MAX_VALUE; min Integer.MAX_VALUE Integer Integer.MAX_VALUE while (c < k ) {
                    if (min > a[y] + Math.abs(h[y] - h[i])) {
                        min = a[y] + Math.abs(h[y] - h[i]);

                    }
                    y--;
                    c++;
                } c < k c k {
                    if (min > a[y] + Math.abs(h[y] - h[i])) {
                        min = a[y] + Math.abs(h[y] - h[i]);

                    }
                    y--;
                    c++;
                } if (min > a[y] + Math.abs(h[y] - h[i])) {
                        min = a[y] + Math.abs(h[y] - h[i]);

                    } min > a[y] + Math.abs(h[y] - h[i]) min a[y] + Math.abs(h[y] - h[i]) a[y] a y Math.abs(h[y] - h[i]) Math.abs Math h[y] - h[i] h[y] h y h[i] h i {
                        min = a[y] + Math.abs(h[y] - h[i]);

                    } min = a[y] + Math.abs(h[y] - h[i]) min a[y] + Math.abs(h[y] - h[i]) a[y] a y Math.abs(h[y] - h[i]) Math.abs Math h[y] - h[i] h[y] h y h[i] h i y-- y c++ c a[i] = min a[i] a i min System.out.println(a[n - 1]) System.out.println System.out System System.out a[n - 1] a n - 1 n 1 {
            System.out.println(h[n-1]-h[0]);
        } System.out.println(h[n-1]-h[0]) System.out.println System.out System System.out h[n-1]-h[0] h[n-1] h n-1 n 1 h[0] h 0 String[] args args static 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()));
        }

        String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }
    } FastReader BufferedReader br; br StringTokenizer st; st public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        } FastReader {
            br = new BufferedReader(new InputStreamReader(System.in));
        } br = new BufferedReader(new InputStreamReader(System.in)) 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();
        } next {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        } while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } st == null || !st.hasMoreElements() st == null st null !st.hasMoreElements() st.hasMoreElements() st.hasMoreElements st {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } IOException e {
                    e.printStackTrace();
                } e.printStackTrace() e.printStackTrace e {
                    st = new StringTokenizer(br.readLine());
                } st = new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) return st.nextToken(); st.nextToken() st.nextToken st int nextInt() {
            return (Integer.parseInt(next()));
        } nextInt {
            return (Integer.parseInt(next()));
        } return (Integer.parseInt(next())); (Integer.parseInt(next())) Integer.parseInt Integer next() next long nextLong() {
            return (Long.parseLong(next()));
        } nextLong {
            return (Long.parseLong(next()));
        } return (Long.parseLong(next())); (Long.parseLong(next())) Long.parseLong Long next() next String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        } nextLine {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        } String s = ""; s "" try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } IOException e {
                e.printStackTrace();
            } e.printStackTrace() e.printStackTrace e {
                s = br.readLine();
            } s = br.readLine() s br.readLine() br.readLine br return s; s
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main{
    static 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()));
        }

        String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }
    }

    public static void main(String[] args) {
        FastReader in = new FastReader();
        int n=in.nextInt();
        int k=in.nextInt();
        int h[]=new int[n];
        for(int i=0;i<n;i++){
            h[i]=in.nextInt();
        }
        int a[]=new int[n];
        if(n>k) {
            a[0] = 0;
            for (int i = 1; i <= k; i++) {
                a[i] = Math.abs(h[i] - h[0]);
            }

            for (int i = k; i < n; i++) {
                int y = i - 1;
                int c = 0;
                int min = Integer.MAX_VALUE;
                while (c < k ) {
                    if (min > a[y] + Math.abs(h[y] - h[i])) {
                        min = a[y] + Math.abs(h[y] - h[i]);

                    }
                    y--;
                    c++;
                }
               // System.out.println(min);
                a[i] = min;
            }

            System.out.println(a[n - 1]);
        }
        else{
            System.out.println(h[n-1]-h[0]);
        }

    }
}
