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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
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;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD2 solver = new TaskD2();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD2 {
        private int MAX = 200000 + 1;
        private long[] sum;
        private int[] size;
        private int k;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            k = in.nextInt();
            Integer[] ar = new Integer[n];
            int max = 0;
            for (int i = 0; i < n; i++) {
                ar[i] = in.nextInt();
                max = Math.max(max, ar[i]);
            }
            long min = Integer.MAX_VALUE;
            if (check(ar, n, k))
                min = 0;
            else {
                sum = new long[MAX];
                size = new int[MAX];
                Arrays.sort(ar);
                for (int i = 0; i < n; i++)
                    fillArray(ar[i]);
                for (int i = 0; i < MAX; i++) {
                    long curAns;
                    if (size[i] >= k)
                        curAns = sum[i];
                    else
                        curAns = Long.MAX_VALUE;
                    min = Math.min(min, curAns);
                }
            }
            out.println(min);
        }

        private boolean check(Integer[] ar, int n, int k) {
            int[] cnt = new int[MAX];
            for (int i = 0; i < n; i++)
                cnt[ar[i]]++;
            for (int i = 1; i < MAX; i++)
                if (cnt[i] >= k)
                    return true;
            return false;
        }

        private void fillArray(int v) {
            int cost = 0;
            while (true) {
                if (size[v] < k) {
                    sum[v] += cost;
                    size[v]++;
                }
                if (v == 0)
                    break;
                cost++;
                v >>= 1;
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}