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.awt.*;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.*;
import java.io.*;
public class Main3 {
    static PrintWriter pr;
    static Scanner scan;
    static BufferedReader br;
    static StringTokenizer st;
    public static void main(String args[]) throws Exception {
        pr = new PrintWriter(System.out);
        scan = new Scanner(System.in);
        br = new BufferedReader(new InputStreamReader(System.in));
        int[] line = intArray(2);
        int n = line[0];
        int k = line[1];
        int[] a = intArray(n);
        int[] sum = new int[200001];
        PriorityQueue<Integer>[] pq = new PriorityQueue[200001];
        for(int i=0;i<200001;i++){
            pq[i] = new PriorityQueue<>(Collections.reverseOrder());
        }
        for(int i=0;i<n;i++){
            int b = a[i];
            int moves=0;
            while(b!=0){
                if(pq[b].size()<k){
                    pq[b].add(moves);
                    sum[b]+=moves;
                }
                else{
                    if(pq[b].peek()>moves){
                        sum[b]+=moves;
                        sum[b]-=pq[b].remove();
                        pq[b].add(moves);
                    }
                }
                moves++;
                b/=2;
            }
            if(pq[b].size()<k){
                pq[b].add(moves);
                sum[b]+=moves;
            }
            else{
                if(pq[b].peek()>moves){
                    sum[b]+=moves;
                    sum[b]-=pq[b].remove();
                }
            }


        }
        int min=Integer.MAX_VALUE;
        for(int i=0;i<200001;i++){
            if(pq[i].size()==k && sum[i]<min){
                //System.out.println(i+" "+sum[i]);
                min = sum[i];
            }
        }
        
        pr.println(min);
        pr.close();
    }
    public static int inputInt() throws IOException{
        return Integer.parseInt(br.readLine());
    }

    public static long inputLong() throws IOException{
        return Long.parseLong(br.readLine());
    }

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

    public static  int[] intArray(int n) throws IOException{
        int a[] = new int[n];
        st = new StringTokenizer(br.readLine());
        for(int i=0;i<n;i++){
            a[i] = Integer.parseInt(st.nextToken());
        }
        return a;
    }

    public static  long[] longArray(int n) throws IOException{
        long a[] = new long[n];
        st = new StringTokenizer(br.readLine());
        for(int i=0;i<n;i++){
            a[i] = Long.parseLong(st.nextToken());
        }
        return a;
    }

    public static String[] stringArray(int n) throws IOException{
        String a[] = new String[n];
        st = new StringTokenizer(br.readLine());
        for(int i=0;i<n;i++){
            a[i] = st.nextToken();
        }
        return a;
    }

    public static long gcd(long a,long b){
        if(b==0){
            return a;
        }
        else{
            return gcd(b,a%b);
        }
    }

    public long max(long a,long b,long c){
        return Math.max(a,Math.max(b,c));
    }
}