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.util.*;
import java.io.*;
import java.math.BigInteger; 

 public class Task{
// taking inputs
 	static long gcd(long a,long b){if(b==0){return a;}return gcd(b,a%b);}

static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static int[] int_arr() throws IOException{String[] a=read().split(" ");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split(" ");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}
// ends

//......................................@uthor_Alx..............................................

public static void main(String[] args) throws  IOException{
	        		  assign();
              int[] nk=int_arr();
              int n=nk[0],k=nk[1];
              int[] arr=int_arr();
              List<Integer> l1=new ArrayList<>();
              for(int x:arr){l1.add(x);}
              Collections.sort(l1);
             for(int i=0;i<n;i++){arr[i]=l1.get(i);}
             long[] pre= new long[n];
             long[] post= new long[n];
             pre[0]=arr[0]; post[n-1]=arr[n-1];
             for(int i=1;i<n;i++){pre[i]=pre[i-1]+arr[i];}
             for(int i=n-2;i>=0;i--){post[i]=post[i+1]+arr[i];}
             long xx=Long.MAX_VALUE;
             for(int i=0;i<n;i++){
             	int s=i-1,c=1;
             	while(i+1<n&&arr[i]==arr[i+1]){i++;c++;}
             	int j=i+1,k1=0;
             	if(c>=k){xx=0;break;}
                 int l=arr[i]-1,r=arr[i]+1;
                 long left=0;
                 long right=0;
                 if(s>=0){left=(long)l*(s+1)-pre[s];}
                 if(n>j){right=post[j]-(long)r*(n-j);}
                 long cost1=0,cost2=0;
                 if(s>=0){
                 	cost1+=left+Math.min(k-c,s+1);
                 	k1=k-c-Math.min(k-c,s+1);
                 	if(k1>0){
                 		cost1+=right+k1;
                 	}
                 }
                 if(j<n) {
                 	cost2+=right+Math.min(k-c,n-j);
                 	k1=k-c-Math.min(k-c,n-j);
                 	if(k1>0){
                 		cost2+=left+k1;
                 	}
                 }
                 if(cost1!=0) xx=Math.min(xx,cost1);
                 if(cost2!=0) xx=Math.min(xx,cost2);
             }
             out.write(xx+" ");
        out.flush();
	        		 
	        	}
	       
	          
	        }