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.util.*;
import java.io.*;
import java.math.*;
 
public class Es4
{
    static IO io = new IO();
    public static void main(String[] args)
    {
		int T = 1;
		while(T-->0){
			int n = io.getInt();
			int k = io.getInt();
			int[] a = new int[n];
			for(int i=0; i<n; i++)
				a[i] = io.getInt();
			Arrays.sort(a);
			long min = 1000000000;
			
			TreeSet<Integer> set = new TreeSet<>();
			set.add(0);
			for(int j=0; j<n; j++){
				int tmp = a[j];
				while(tmp > 0){
					set.add(tmp);
					tmp = tmp/2;
				}
			}
			
			
			for(Integer trg : set){
				int[] costs = new int[n];
				for(int j=0; j<n; j++){
					int tmp = a[j];
					while(tmp >= trg){
						if(tmp == trg)
							break;
						costs[j]++;
						tmp = tmp/2;
					}
					if(tmp!=trg)
						costs[j]=10000000;
					
					//io.print(costs[j] +" ");
				}
				//io.println();
				Arrays.sort(costs);
				long sum = 0;
				for(int j=0; j<k; j++)
					sum+=costs[j];
				
				//io.println(i+": "+sum);
				
				min = Math.min(min, sum);
			}
			
			io.println(min);
			
		}
		
		
        io.close();
    }
}
 
 
 
class IO extends PrintWriter {
	public IO() {
        super(new BufferedOutputStream(System.out));
        r = new BufferedReader(new InputStreamReader(System.in));
    }
 
    public IO(String fileName) {
        super(new BufferedOutputStream(System.out));
        try{
            r = new BufferedReader(new FileReader(fileName));
        } catch (FileNotFoundException e) {
            this.println("File Not Found");
        }
    }
 
    public boolean hasMoreTokens() {
        return peekToken() != null;
    }
 
    public int getInt() {
        return Integer.parseInt(nextToken());
    }
 
    public double getDouble() {
        return Double.parseDouble(nextToken());
    }
 
    public long getLong() {
        return Long.parseLong(nextToken());
    }
 
    public String getWord() {
        return nextToken();
    }
 
	public String getLine(){
        try{
            st = null;
            return r.readLine();
        }
        catch(IOException ex){}
        return null;
    }
	
 
    private BufferedReader r;
    private String line;
    private StringTokenizer st;
    private String token;
 
    private String peekToken() {
        if (token == null)
            try {
                while (st == null || !st.hasMoreTokens()) {
                    line = r.readLine();
                    if (line == null) return null;
                    st = new StringTokenizer(line);
                }
                token = st.nextToken();
            } catch (IOException e) { }
        return token;
    }
 
    private String nextToken() {
        String ans = peekToken();
        token = null;
        return ans;
    }
}
