Problem: You are given the array a consisting of n elements and the integer k ≤ n.

You want to obtain at least k equal elements in the array a. In one move, you can make one of the following two operations:

  * Take one of the minimum elements of the array and increase its value by one (more formally, if the minimum value of a is mn then you choose such index i that a_i = mn and set a_i := a_i + 1); 
  * take one of the maximum elements of the array and decrease its value by one (more formally, if the maximum value of a is mx then you choose such index i that a_i = mx and set a_i := a_i - 1). 



Your task is to calculate the minimum number of moves required to obtain at least k equal elements in the array.

Input

The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of elements in a and the required number of equal elements.

The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9), where a_i is the i-th element of a.

Output

Print one integer — the minimum number of moves required to obtain at least k equal elements in the array.

Examples

Input


6 5
1 2 2 4 2 3


Output


3


Input


7 5
3 3 2 1 1 1 3


Output


4

Solution (in JAVA):

Solution:
import java.io.*;
import java.util.*;

public class ProblemF {

    public static InputStream inputStream = System.in;

    public static OutputStream outputStream = System.out;

    public static void main(String[] args) {
        MyScanner scanner = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        int n = scanner.nextInt();
        int k = scanner.nextInt();
        List<Long> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(scanner.nextLong());
        }

        Collections.sort(list);
        List<Pair<Long, Long>> pairs = new ArrayList<>();
        long count = 1;
        for (int i = 1; i < n; i++) {
            if (list.get(i).equals(list.get(i - 1))) {
                count++;
            } else {
                pairs.add(new Pair<>(list.get(i - 1), count));
                count = 1;
            }
        }
        pairs.add(new Pair<>(list.get(n - 1), count));

        long[] dpLeft = new long[pairs.size()];
        count = pairs.get(0).second;
        for (int i = 1; i < pairs.size(); i++) {
            dpLeft[i] = dpLeft[i - 1] + count * (pairs.get(i).first - pairs.get(i - 1).first);
            count += pairs.get(i).second;
        }

        long[] dpRight = new long[pairs.size()];
        count = pairs.get(pairs.size() - 1).second;
        for (int i = pairs.size() - 2; i >= 0; i--) {
            dpRight[i] = dpRight[i + 1] + count * (pairs.get(i + 1).first - pairs.get(i).first);
            count += pairs.get(i).second;
        }

        long ans = Long.MAX_VALUE;
        count = 0;
        for (int i = 0; i < pairs.size(); i++) {
            long x = Long.MAX_VALUE;
            if (pairs.get(i).second >= k) {
                x = 0;
            } else {
                if (n - count >= k) {
                    x = (pairs.get(i + 1).first - pairs.get(i).first) * (k - pairs.get(i).second) + dpRight[i + 1];
                }
                if (count + pairs.get(i).second >= k) {
                    x = Math.min(x, (pairs.get(i).first - pairs.get(i - 1).first) * (k - pairs.get(i).second) + dpLeft[i - 1]);
                }
                if (i != 0 && i != pairs.size() - 1) {
                    long p = dpLeft[i - 1] + dpRight[i + 1];
                    p += count * (pairs.get(i).first - pairs.get(i - 1).first);
                    p += (n - count - pairs.get(i).second) * (pairs.get(i + 1).first - pairs.get(i).first);
                    p = p - (n - k);
                    x = Math.min(x, p);
//                    long p = dpLeft[i - 1] + dpRight[i + 1];
//                    if (pairs.get(i + 1).first - pairs.get(i).first > pairs.get(i).first - pairs.get(i - 1).first) {
//                        p += (pairs.get(i).first - pairs.get(i - 1).first) * Math.min(count, k - pairs.get(i).second);
//                        if (pairs.get(i).second + count < k) {
//                            p += (pairs.get(i + 1).first - pairs.get(i).first) * (k - (count + pairs.get(i).second));
//                        } else {
//                            p = Long.MAX_VALUE;
//                        }
//                        if (p == 253243) {
//                            out.println("x " + i + " " + pairs.get(i).first + " " + pairs.get(i).second);
//                            out.println(dpLeft[i - 1]);
//                            out.println(dpRight[i + 1]);
//                            out.println(pairs.get(i - 1).first + " " + pairs.get(i).first + " " + pairs.get(i + 1).first);
//                            out.println(count);
//                            int c1 = 0, c2 = 0;
//                            long ll = 0;
//                            for (long r : list) {
//                                if (r < pairs.get(i).first) {
//                                    c1++;
//                                } else if (r == pairs.get(i).first) {
//                                    c2++;
//                                }
//                                ll = ll + Math.abs(r - pairs.get(i).first);
//                            }
//                            out.println(c1 + " " + c2);
//                            out.println(ll);
//                        }
//                    } else {
//                        p += (pairs.get(i + 1).first - pairs.get(i).first) * Math.min(n - (count + pairs.get(i).second), k - pairs.get(i).second);
//                        if (n - count < k) {
//                            p += (pairs.get(i).first - pairs.get(i - 1).first) * (k - (n - count));
//                        } else {
//                            p = Long.MAX_VALUE;
//                        }
//                        if (p == 253243) {
//                            out.println("y " + i + " " + pairs.get(i).first + " " + pairs.get(i).second);
//                        }
//                    }
//                    x = Math.min(x, p);
                }
            }
            count += pairs.get(i).second;
            ans = Math.min(ans, x);
        }

        out.println(ans);


        out.flush();
    }

    private static class MyScanner {
        private BufferedReader bufferedReader;
        private StringTokenizer stringTokenizer;

        private MyScanner(InputStream inputStream) {
            bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        }

        private String next() {
            while (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
                try {
                    stringTokenizer = new StringTokenizer(bufferedReader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return stringTokenizer.nextToken();
        }

        private int nextInt() {
            return Integer.parseInt(next());
        }

        private long nextLong() {
            return Long.parseLong(next());
        }

        private double nextDouble() {
            return Double.parseDouble(next());
        }

        private String nextLine() {
            String str = "";
            try {
                str = bufferedReader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    private static class Pair<F, S> {

        private F first;

        private S second;

        public Pair() {
        }

        public Pair(F first, S second) {
            this.first = first;
            this.second = second;
        }
    }
}