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.StringTokenizer;

public class Main
{
	public static void main(String[] args) {
		new Thread(null, new Runnable() {
			public void run() {
                solve();
            }
        }, "1", 1 << 26).start();
	}
	static void solve () {
		FastReader fr =new FastReader();	PrintWriter op =new PrintWriter(System.out);
 		
 		int n =fr.nextInt() ,i ,j ,k ;	long a[][] =new long[n][2] ,dm ,l ,K =fr.nextLong() ;
 		for (i =0 ; i<n ; ++i)	a[i][0] =fr.nextLong() ;	sort (a,0,n-1) ;	j =-1 ;
 		for (i =0 ; i<n ; ) {
 			a[++j][0] =a[i][0] ;	k =i ;
 			while (i<n && a[i][0]==a[k][0])	++i ;	a[j][1] =i-k ;
 		}
 		dm =0 ;	for (i =0 ; i<=j ; ++i)	dm =Math.max(dm,a[i][1]) ;
 		if (dm>=K)	op.println("0") ;
 		else {
 			long dp[][][] =new long[2][j+1][2] ,ans ;	dp[0][0][1] =a[0][1] ;
 			for (i =1 ; i<=j ; ++i) {
 				dm =a[i][0]-a[i-1][0] ;	dp[0][i][1] =a[i][1] + dp[0][i-1][1] ;
 				dm *= dp[0][i-1][1] ;	dp[0][i][0] =dp[0][i-1][0] + dm ;
 			}
 			dp[1][j][1] =a[j][1] ;
 			for (i =j-1 ; i>-1 ; --i) {
 				dm =a[i+1][0]-a[i][0] ;	dp[1][i][1] =a[i][1] + dp[1][i+1][1] ;
 				dm *= dp[1][i+1][1] ;	dp[1][i][0] =dp[1][i+1][0] + dm ;
 			}

 			dm =dp[1][1][0] + dp[1][1][1] * (a[1][0] - a[0][0] - 1) ; 
 			l =Math.min(dp[1][1][1] , K-a[0][1]) ;	dm += l ;	ans =dm ;
 			
 			for (i =1 ; i<j ; ++i) {
 				dm =dp[0][i-1][0] + dp[0][i-1][1] * (a[i][0] - a[i-1][0] - 1) ;
 				l =Math.min(dp[0][i-1][1] , K-a[i][1]) ;	dm += l ;
 				
 				if (l+a[i][1] < K) {
 					dm += (dp[1][i+1][0] + dp[1][i+1][1] * (a[i+1][0] - a[i][0] - 1)) ;
 					l =Math.min(dp[1][i+1][1] , K - l - a[i][1]) ;	dm += l ; 
 				}
 				ans =Math.min(ans , dm) ;

 				dm =dp[1][i+1][0] + dp[1][i+1][1] * (a[i+1][0] - a[i][0] - 1);
 				l =Math.min(dp[1][i+1][1] , K-a[i][1]) ;	dm += l ;
 				
 				if (l+a[i][1] < K) {
 					dm += (dp[0][i-1][0] + dp[0][i-1][1] * (a[i][0] - a[i-1][0] - 1)) ;
 					l =Math.min(dp[0][i-1][1] , K - l - a[i][1]) ;	dm += l ;
 				}
 				ans =Math.min(ans , dm) ;
 			}
 			
 			dm =dp[0][j-1][0] + dp[0][j-1][1] * (a[j][0] - a[j-1][0] - 1) ;
 			l =Math.min(dp[0][j-1][1] , K-a[j][1]) ;	dm += l ;
 			ans =Math.min(ans , dm) ;	op.println(ans) ;
 		}
		op.flush();	op.close();
	}
	public static void sort(long[][] arr , int l , int u) {
		int m ;
 
		if(l < u){
			m =(l + u)/2 ;
 
			sort(arr , l , m);	sort(arr , m + 1 , u);
 
			merge(arr , l , m , u);
		}
	} 
	public static void merge(long[][]arr , int l , int m , int u) {
		long[][] low = new long[m - l + 1][2];
 
		long[][] upr = new long[u - m][2];
 
		int i ,j =0 ,k =0 ;
 
		for(i =l;i<=m;i++){
			low[i - l][0] =arr[i][0];
			low[i - l][1] =arr[i][1];
		}
 
		for(i =m + 1;i<=u;i++){
			upr[i - m - 1][0] =arr[i][0];
			upr[i - m - 1][1] =arr[i][1];
		}
 
		i =l;
 
		while((j < low.length) && (k < upr.length))
		{
			if(low[j][0] < upr[k][0])
			{
				arr[i][0] =low[j][0];
				arr[i++][1] =low[j++][1];
			}
			else
			{
				arr[i][0] =upr[k][0];
				arr[i++][1] =upr[k++][1];
			
			}
		}
 
		while(j < low.length)
		{
			arr[i][0] =low[j][0];
			arr[i++][1] =low[j++][1];
		}
 
		while(k < upr.length)
		{
			arr[i][0] =upr[k][0];
			arr[i++][1] =upr[k++][1];
		}
	}
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br =new BufferedReader(new InputStreamReader(System.in));
		}

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

		String nextLine() {
			String str ="";

			try
			{
				str =br.readLine();
			}
			catch(IOException e)
			{
				e.printStackTrace();
			}

			return str;
		}

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

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