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 Main {


    public static void main(String[] args) throws IOException {
//        br = new BufferedReader(new FileReader(new File("subtract.in")));
//        out = new PrintWriter(new File("subtract.out"));
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        int PUTEN = 1;
        for (int POMOGI = 0; POMOGI < PUTEN; POMOGI++) {
            int n = nextInt();
            int k = nextInt();
            ArrayList<Long> a = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                a.add(nextLong());
            }
            Collections.sort(a);
            int ind = 0;
            while (ind < n) {
                int cnt = 1;
                while (ind + 1 < n && a.get(ind) == a.get(ind + 1)) {
                    ind++;
                    cnt++;
                }
                if (cnt >= k) {
                    out.println(0);
                    out.close();
                    return;
                }
                ind++;
            }
            long[] pr = new long[n];
            long suf[] = new long[n];
            suf[n - 1] = a.get(n - 1);
            pr[0] = a.get(0);
            for (int i = 1; i < n; i++) {
                pr[i] = pr[i - 1] + a.get(i);
                suf[n - i - 1] = suf[n - i] + a.get(n - i - 1);
            }
            long ans = Long.MAX_VALUE;
            for (int i = 0; i < n; i++) {
                long pop_pr = 0;
                long pop_suf = 0;
                if (i != 0) pop_pr = (i * a.get(i)) - pr[i - 1];
                if (i != n - 1) pop_suf = suf[i + 1] - ((n - i - 1) * a.get(i));

                ind = i;
                while (ind + 1 < n && a.get(ind) == a.get(ind + 1)) {
                    ind++;
                }
                int cnt_now = ind - i + 1;
                long now = pop_suf;
                cnt_now += n - ind - 1;
                if (cnt_now >= k) {
                    now -= cnt_now - k;
                    ans = Math.min(ans, now);
                } else {
                    now += pop_pr;
                    cnt_now += i;
                    now -= cnt_now - k;
                    ans = Math.min(ans, now);
                }

                cnt_now = ind - i + 1;
                now = pop_pr;
                cnt_now += i;
                if (cnt_now >= k) {
                    now -= cnt_now - k;
                    ans = Math.min(ans, now);
                }else {
                    now += pop_suf;
                    cnt_now += n - ind - 1;
                    now -= cnt_now - k;
                    ans = Math.min(ans, now);
                }
                i = ind;
            }
            out.println(Math.max(ans, 0));
        }
        out.close();
    }

    static BufferedReader br;
    static PrintWriter out;
    static StringTokenizer in = new StringTokenizer("");

    static int gcd(int a, int b) {
        if (a == 0 || b == 0) return (a + b);
        if (a > b) return gcd(a % b, b);
        else return gcd(a, b % a);
    }

    static String next() throws IOException {
        while (!in.hasMoreTokens()) {
            in = new StringTokenizer(br.readLine());
        }
        return in.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

}

class Point {
    int kur;
    int pet;


    public Point(int kur, int pet) {
        this.kur = kur;
        this.pet = pet;
    }
}