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
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.TreeMap;
import java.util.StringTokenizer;
import java.util.Map.Entry;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        FMakeKEqual solver = new FMakeKEqual();
        solver.solve(1, in, out);
        out.close();
    }

    static class FMakeKEqual {
        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            int n = sc.nextInt();
            long k = sc.nextInt();
            TreeMap<Integer, Integer> tm = new TreeMap<>();
            for (int i = 0; i < n; i++) {
                int tmp = sc.nextInt();
                if (tm.containsKey(tmp)) {
                    tm.replace(tmp, tm.get(tmp) + 1);
                    if (tm.get(tmp) >= k) {
                        pw.println(0);
                        pw.flush();
                        return;
                    }
                } else {
                    tm.put(tmp, 1);
                    if (tm.get(tmp) >= k) {
                        pw.println(0);
                        pw.flush();
                        return;
                    }
                }
            }
            long[] arr = new long[tm.size()];
            long[] count = new long[tm.size()];
            long[] precount = new long[tm.size()];
            long[] sufcount = new long[tm.size()];
            // pw.println(tm);
            for (int i = 0; i < arr.length; i++) {
                arr[i] = tm.firstKey();
                count[i] = tm.pollFirstEntry().getValue();
                if (i == 0) precount[i] = count[i];
                else precount[i] = precount[i - 1] + count[i];
                if (i == 0) sufcount[i] = n;
                else sufcount[i] = n - precount[i - 1];
            }
            long[] pre = new long[arr.length];
            pre[0] = 0;
            for (int i = 1; i < arr.length; i++) {
                pre[i] = 1l * (precount[i - 1]) * (arr[i] - arr[i - 1]) + pre[i - 1];
            }
            long[] suf = new long[arr.length];
            suf[arr.length - 1] = 0;
            for (int i = arr.length - 2; i >= 0; i--) {
                suf[i] = 1l * (sufcount[i + 1]) * (arr[i + 1] - arr[i]) + suf[i + 1];
            }
            long ans = Long.MAX_VALUE;
            for (int i = 0; i < arr.length; i++) {
                if (count[i] >= k) ans = 0;
            }
            for (int i = 1; i < arr.length; i++) {
                if (precount[i] >= k) {
                    ans = Math.min(ans, pre[i - 1] + 1l * (k - count[i]) * (arr[i] - arr[i - 1]));
                    break;
                }
            }
            for (int i = arr.length - 2; i >= 0; i--) {
                if (sufcount[i] >= k) {
                    ans = Math.min(ans, suf[i + 1] + 1l * (k - count[i]) * (arr[i + 1] - arr[i]));
                    break;
                }
            }

            for (int i = 1; i < arr.length - 1; i++) {
                ans = Math.min(ans, Math.min((k - precount[i] > 0) ? pre[i] + suf[i + 1] + 1l * (k - precount[i]) + suf[i + 1] * (arr[i + 1] - arr[i] - 1) : Long.MAX_VALUE, (k - sufcount[i] > 0) ? pre[i - 1] + suf[i] + 1l * (k - sufcount[i]) + precount[i - 1] * (arr[i] - arr[i - 1] - 1) : Long.MAX_VALUE));

                //309 116167 135579 500 561987385 561987382 501 115668 137079 561987381
            }
            pw.println(ans);
            pw.flush();

        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

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

    }
}

