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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.StringTokenizer;

public class D {
    static BufferedReader br;
    static StringTokenizer st;
    static PrintWriter pw;

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

    static int nextInt() {
        return Integer.parseInt(nextToken());
    }

    static long nextLong() {
        return Long.parseLong(nextToken());
    }

    static String nextLine() throws IOException {
        return br.readLine();
    }

    static char nextChar() throws IOException {
        return (char) br.read();
    }

    public static void main(String[] args) {
        br = new BufferedReader(new InputStreamReader(System.in));
        pw = new PrintWriter(System.out);
        run();
        pw.close();
    }

    static int k;

    private static void run() {
        int n = nextInt();
        k = nextInt();
        ArrayList<ArrayList<Integer>> array = new ArrayList<>();

        ArrayList<Integer> a = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            a.add(nextInt());
        }
        Collections.sort(a);
        for (int i = 0; i < n; i++) {
            int x = a.get(i);
            array.add(new ArrayList<>());
            while (x > 0) {
                array.get(i).add(x % 2);
                x /= 2;
            }
        }
        dfs(array, 0);
        pw.println(ans);
    }

    static int ans = Integer.MAX_VALUE;

    private static void dfs(ArrayList<ArrayList<Integer>> array, int p) {
        ArrayList<ArrayList<Integer>> first = new ArrayList<>();
        ArrayList<ArrayList<Integer>> second = new ArrayList<>();
        first.add(array.get(0));
        for (int j = 1; j < array.size(); j++) {
            if (array.get(j).get(array.get(j).size() - 1 - p) == array.get(0).get(array.get(0).size() - 1 - p)) {
                first.add(array.get(j));
            } else {
                second.add(array.get(j));
            }
        }
        if (first.size() >= k) {

            int ll = 0;
            for (int i = 0; i < k; i++) {
                ll += first.get(i).size() - p - 1;
            }
            ans = Math.min(ll, ans);
            first = sd(first, p);
            if (first.size() >= k) {
                dfs(first, p + 1);
            }
        }
        if (second.size() >= k) {
            int ll = 0;
            for (int i = 0; i < k; i++) {
                ll += second.get(i).size() - p - 1;
            }
            ans = Math.min(ll, ans);
            second = sd(second, p);
            if (second.size() >= k) {
                dfs(second, p + 1);
            }
        }
    }

    private static ArrayList<ArrayList<Integer>> sd(ArrayList<ArrayList<Integer>> first, int p) {
        int o = 0;
        for (int i = 0; i < first.size(); i++) {
            if (first.get(i).size() <= p + 1) {
                o++;
            } else {
                break;
            }
        }
        ArrayList<ArrayList<Integer>> ans = new ArrayList<>();
        for (int i = o; i < first.size(); i++) {
            ans.add(first.get(i));
        }
        return ans;
    }
}
