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.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Solve6 {

    public static void main(String[] args) throws IOException {
        PrintWriter pw = new PrintWriter(System.out);
        new Solve6().solve(pw);
        pw.flush();
        pw.close();
    }

    public void solve(PrintWriter pw) throws IOException {
        FastReader sc = new FastReader();
        int n = sc.nextInt(), k = sc.nextInt();
        ArrayList<Integer> a = new ArrayList();
        final int MAX = (int) 2E+5;
        int[] freq = new int[MAX + 1];
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            freq[x]++;
            if (freq[x] == 1) {
                a.add(x);
            }
        }
        n = a.size();
        HashMap<Integer, TreeMap<Integer, Integer>> hm = new HashMap();
        for (int i = 0; i < n; i++) {
            int x = a.get(i);
            int f = freq[x];
            int cnt = 0;
            while (x >= 1) {
                TreeMap<Integer, Integer> temp = new TreeMap();
                if (hm.get(x) != null) {
                    temp = hm.get(x);
                }
                temp.put(cnt, temp.getOrDefault(cnt, 0) + f);
                hm.put(x, temp);
                ++cnt;
                x /= 2;
            }
        }
        int min = Integer.MAX_VALUE;
        for (Map.Entry<Integer, TreeMap<Integer, Integer>> entry : hm.entrySet()) {
            TreeMap<Integer, Integer> tm = entry.getValue();
            int cnt = k;
            int temp = 0;
            for (Map.Entry<Integer, Integer> entry2 : tm.entrySet()) {
                Integer key = entry2.getKey(), val = entry2.getValue();
                if (cnt <= val) {
                    temp += cnt * key;
                    cnt = 0;
                    break;
                } else {
                    temp += val * key;
                    cnt -= val;
                }
            }
            if (cnt == 0) {
                min = Math.min(min, temp);
            }
        }
        pw.println(min);
    }

    static class FastReader {

        StringTokenizer st;
        BufferedReader br;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (Exception e) {
            }
        }

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

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

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

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

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

        public boolean hasNext() throws IOException {
            if (st != null && st.hasMoreTokens()) {
                return true;
            }
            String s = br.readLine();
            if (s == null || s.isEmpty()) {
                return false;
            }
            st = new StringTokenizer(s);
            return true;
        }
    }
}
