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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;


public class Main {
    static int i, j, k, n, m, t, y, x, sum=0;
    static long mod = 998244353;
    static FastScanner fs = new FastScanner();
    static PrintWriter out = new PrintWriter(System.out);
    static String str;
    static long ans;

    public static void main(String[] args) {
        t = 1;

        while (t-- >0){

            n = fs.nextInt();

            k = fs.nextInt();

            int[] arr = new int[n];

            int[] count = new int[200005];


            for(i=0;i<n;i++){
                arr[i]=fs.nextInt();
                count[arr[i]]++;
            }

            ruffleSort(arr);

            j=1;

            ans = 0;

            int a =0;

            for(i=0;i<k;i++){
                while(arr[i]>=j) {
                        j *= 2;
                        a++;
                    }
                    ans+=a;
            }


            for(i=1;i<200005;i++){
                int ansHere = 0;

                int tempEle = count[i];

                int c=2;
                a = 1;

                for(j=2*i;j<200005; j*=2){

                    if(tempEle>=k)
                        break;

                    for(int in=j;in<j+c && in <200005;in++){
                        if(count[in]!=0){
                            int d = Math.min( k - tempEle, count[in]);

                            tempEle+=d;
                            ansHere+=(d*a);

                        }
                    }

                    c*=2;
                    a++;
                }

                if(tempEle>=k && ansHere<ans) {
                    ans = ansHere;

                }

            }

            out.print(ans);

        }
        out.close();
    }


    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

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

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

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

    static class Pair implements Comparable<Pair>{
        long first, second;

        public Pair(long first, long second) {
            this.first = first;
            this.second = second;

        }

        @Override
        public int compareTo(Pair o) {
            return Long.compare(first, o.first);
        }
    }

    static void ruffleSort(int[] a) {
        //ruffle
        int n=a.length;
        Random r=new Random();
        for (int i=0; i<a.length; i++) {
            int oi=r.nextInt(n), temp=a[i];
            a[i]=a[oi];
            a[oi]=temp;
        }

        //then sort
        Arrays.sort(a);
    }

    static void ruffleSort(long[] a) {
        //ruffle
        int n=a.length;
        Random r=new Random();
        for (int i=0; i<a.length; i++) {
            int oi=r.nextInt(n); long temp=a[i];
            a[i]=a[oi];
            a[oi]=temp;
        }

        //then sort
        Arrays.sort(a);
    }


}