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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jenish
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D2EqualizingByDivisionHardVersion solver = new D2EqualizingByDivisionHardVersion();
        solver.solve(1, in, out);
        out.close();
    }

    static class D2EqualizingByDivisionHardVersion {
        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();
            int k = in.scanInt();
            int count[] = new int[200000 + 5];
            int step[] = new int[200000 + 5];
            long ans = Long.MAX_VALUE;
            long sum = 0;
            int arr[] = new int[n];
            in.scanInt(arr);
            CodeX.sort(arr);
            for (int i = 0; i < n; i++) {
                int c = 0;
                int x = arr[i];
                while (x > 0) {
                    count[x]++;
                    step[x] += c;
                    c++;
                    if (count[x] >= k) {
                        ans = Math.min(step[x], ans);
                    }
                    x = x / 2;
                }
                sum += c;
                if (i + 1 >= k) {
                    ans = Math.min(ans, sum);
                }
//            count[0]++;
//            count[0] += c;
//            if (count[0] >= k) {
//                ans = Math.min(step[0], ans);
//            }

            }

            out.println(ans);
        }

    }

    static class CodeX {
        public static void sort(int arr[]) {
            merge_sort(arr, 0, arr.length - 1);
        }

        private static void merge_sort(int A[], int start, int end) {
            if (start < end) {
                int mid = (start + end) / 2;
                merge_sort(A, start, mid);
                merge_sort(A, mid + 1, end);
                merge(A, start, mid, end);
            }

        }

        private static void merge(int A[], int start, int mid, int end) {
            int p = start, q = mid + 1;
            int Arr[] = new int[end - start + 1];
            int k = 0;

            for (int i = start; i <= end; i++) {
                if (p > mid)
                    Arr[k++] = A[q++];

                else if (q > end)
                    Arr[k++] = A[p++];

                else if (A[p] < A[q])
                    Arr[k++] = A[p++];

                else
                    Arr[k++] = A[q++];
            }
            for (int i = 0; i < k; i++) {
                A[start++] = Arr[i];
            }

        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int INDEX;
        private BufferedInputStream in;
        private int TOTAL;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (INDEX >= TOTAL) {
                INDEX = 0;
                try {
                    TOTAL = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (TOTAL <= 0) return -1;
            }
            return buf[INDEX++];
        }

        public int scanInt() {
            int I = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    I *= 10;
                    I += n - '0';
                    n = scan();
                }
            }
            return neg * I;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

        public void scanInt(int[] A) {
            for (int i = 0; i < A.length; i++) A[i] = scanInt();
        }

    }
}

