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:
/*
 ID: tommatt1
 LANG: JAVA
 TASK: 
*/
import java.util.*;
import java.io.*;
public class cf1328f{

	public static void main(String[] args)throws IOException {
		BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		//BufferedReader bf=new BufferedReader(new FileReader("cf1328f.in"));
		//PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("cf1328f.out")));
		StringTokenizer st=new StringTokenizer(bf.readLine());
		int n=Integer.parseInt(st.nextToken());
		int k=Integer.parseInt(st.nextToken());
		int[] a=new int[n];
		st=new StringTokenizer(bf.readLine());
		for(int i=0;i<n;i++) {
			a[i]=Integer.parseInt(st.nextToken());
		}
		a=radixSort(a);
		long[] b=new long[n+1];
		for(int i=0;i<n;i++) {
			b[i+1]=b[i]+a[i];
		}
		int i=0;
		int j=1;
		int nst=0;
		long ans=Long.MAX_VALUE;
		for(;i<n;i=nst) {
			for(;j<=n&&a[j-1]==a[i];j++) {
				long cur=a[i];
				long psum=(long)i*(cur-1)-b[i];
				long ssum=b[n]-b[j]-(long)(n-j)*(cur+1);
				long dif=j-i;
				if(j-i>=k) {
					ans=0;
				}
				if(j>=k) {
					ans=Math.min(ans, psum+k-dif);
				}
				if(n-i>=k) {
					ans=Math.min(ans, ssum+k-dif);
				}
				ans=Math.min(ans, ssum+psum+k-dif);
			}
			nst=j-1;
		}
		out.println(Math.max(0,ans));
		out.close();
	}
	public static int[] radixSort(int[] a)
	{
		int[] na = new int[a.length];
		{
			int[] b = new int[65537];
			for(int i = 0;i < a.length;i++)b[1+(a[i]&0xffff)]++;
			for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
			for(int i = 0;i < a.length;i++)na[b[a[i]&0xffff]++] = a[i];
			int[] c = a; a = na;na = c;
		}
		{
			int[] b = new int[65537];
			for(int i = 0;i < a.length;i++)b[1+(a[i]>>>16)]++;
			for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
			for(int i = 0;i < a.length;i++)na[b[a[i]>>>16]++] = a[i];
			int[] c = a; a = na;na = c;
		}
		return a;
	}
 
}