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.*;
import java.util.*;

/*
Прокрастинирую
*/

public class Main {

    static FastReader in;
    static PrintWriter out;
    static Random rand = new Random();
    static final int INF = (int) (1e9 + 10);
    static final long IINF = (long) (2e18 + 10);
    static final int MOD = (int) (1e9 + 7);
    static final int N = (int) (1e5 + 5);
    static final int LOGN = 20;

    static void solve() {
        int n = in.nextInt();
        int k = in.nextInt();

        TreeMap<Integer, Integer> map = new TreeMap<>();
        for (int i = 0; i < n; i++) {
            int a = in.nextInt();
            map.putIfAbsent(a, 0);
            map.put(a, map.get(a) + 1);
        }

        int m = map.size();
        int[][] a = new int[m][2];
        int ind = 0;
        for (Map.Entry<Integer, Integer> e : map.entrySet()) {
            if (e.getValue() >= k) {
                out.println(0);
                return;
            }
            a[ind][0] = e.getKey();
            a[ind][1] = e.getValue();
            ind++;
        }

        long[] prefSum = new long[m];
        long sum = (long) a[0][0] * a[0][1];
        int cnt = a[0][1];
        for (int i = 1; i < m; i++) {
            prefSum[i] = (long) (a[i][0] - 1) * cnt - sum;
            sum += (long) a[i][0] * a[i][1];
            cnt += a[i][1];
        }

        long[] suffSum = new long[m];
        sum = (long) a[m - 1][0] * a[m - 1][1];
        cnt = a[m - 1][1];
        for (int i = m - 2; i >= 0; i--) {
            suffSum[i] = sum - (long) (a[i][0] + 1) * cnt;
            sum += (long) a[i][0] * a[i][1];
            cnt += a[i][1];
        }

        long ans = IINF;
        cnt = 0;
        for (int i = 0; i < m; i++) {
            long num = prefSum[i] + suffSum[i] + k - a[i][1];
            if (cnt + a[i][1] >= k) {
                num = Math.min(num, prefSum[i] + k - a[i][1]);
            }
            if (n - cnt >= k) {
                num = Math.min(num, suffSum[i] + k - a[i][1]);
            }
            ans = Math.min(ans, num);
            cnt += a[i][1];
        }

        out.println(ans);
    }

    public static void main(String[] args) throws FileNotFoundException {
        in = new FastReader(System.in);
//        in = new FastReader(new FileInputStream("connect.in"));
        out = new PrintWriter(System.out);
//        out = new PrintWriter(new FileOutputStream("connect.out"));


        int q = 1;
//        q = in.nextInt();

        while (q-- > 0) {
            solve();
        }

        out.close();
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

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

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

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

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(nextLine());
            }
            return st.nextToken();
        }

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