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
// Don't place your source in a package
import java.lang.reflect.Array;
import java.text.DecimalFormat;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
import java.util.stream.Stream;


// Please name your class Main
public class Main {
    static FastScanner fs=new FastScanner();
    static class FastScanner {//scanner from SecondThread
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        public String next() {
            while (!st.hasMoreElements())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }
        int Int() {
            return Integer.parseInt(next());
        }

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

        String Str(){
            return next();
        }
    }


    public static void main (String[] args) throws java.lang.Exception {
        PrintWriter out = new PrintWriter(System.out);



        int T=1;
        for(int t=0;t<T;t++){
            int n=Int();int k=Int();
            int A[]=new int[n];
            for(int i=0;i<n;i++){
                A[i]=Int();
            }

            Solution sol=new Solution();
            sol.solution(out,A,k);
        }
        out.flush();

    }

    public static int Int(){
        return fs.Int();
    }
    public static long Long(){
        return fs.Long();
    }
    public static String Str(){
        return fs.Str();
    }

}



class Solution{
    public void solution(PrintWriter out,int A[],int k){
        sort(A);


        long res=Long.MAX_VALUE;
        long pre[]=new long[A.length];
        pre[0]=A[0];
        for(int i=1;i<A.length;i++){
            pre[i]=pre[i-1]+A[i];
        }

        for(int i=0;i<A.length;i++){
            int j=i;
            long cnt=0;
            while(j<A.length&&A[j]==A[i]){
                j++;cnt++;
            }
            if(cnt>=k){
                out.println(0);
                return;
            }

            long sum1=0,sum2=0;
            long leftcnt=i;
            long rightcnt=A.length-j;

            long need1=0;long need2=0;
            long needcnt1=k-cnt;;long needcnt2=k-cnt;
            if(i-1>=0)need1=leftcnt*(A[i]-1)-pre[i-1];
            if(i+1<A.length)need2=(pre[A.length-1]-pre[j-1])-rightcnt*(A[i]+1);

            //try use need1 first and then try need2 first
            sum1+=need1;
            if(needcnt1>=leftcnt){
                needcnt1-=leftcnt;
                sum1+=leftcnt;
                if(needcnt1>0){
                    sum1+=need2;
                    sum1+=needcnt1;
                }
            }
            else{
                sum1+=needcnt1;
            }


            sum2+=need2;
            if(needcnt2>=rightcnt){
                needcnt2-=rightcnt;
                sum2+=rightcnt;
                if(needcnt2>0){
                    sum2+=need1;
                    sum2+=needcnt2;
                }
            }
            else{
                sum2+=needcnt2;
            }
            res=Math.min(res,Math.min(sum1,sum2));
            i=j-1;
        }
        out.println(res);
    }

    public void sort(int A[]){
        PriorityQueue<Integer>pq=new PriorityQueue<>();
        for(int i:A)pq.add(i);
        for(int i=0;i<A.length;i++)A[i]=pq.poll();
    }
}




