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.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader sc = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, sc, out);
        out.close();
    }

    static class Task {
    	public static final int Max=(1<<18)+10;
    	
        public void solve(int testNumber, InputReader sc, PrintWriter out) {
            int n=sc.nextInt();
            int k=sc.nextInt();
            int[] a=new int[n+1];
            int[] cnt=new int[Max];
            int[] pre=new int[Max];
            
            for(int i=1;i<=n;i++) {
            	a[i]=sc.nextInt();
            	cnt[a[i]]++;
            }
            int index=0;
            int s=cnt[Max-1];
            for(int i=Max-2;i>=0;i--) {
            	s+=cnt[i];
            	if(s>=k) {
            		index=i;
            		break;
            	}
            }
            pre[0]=cnt[0];
            for(int i=1;i<Max;i++)
            	pre[i]=pre[i-1]+cnt[i];
            int ans=Integer.MAX_VALUE;
            for(int i=index;i>=0;i--) {
            	int now=k-Math.min(k,cnt[i]);
            	int x=1;
            	int count=0;
            	boolean jud=now==0;
            	if(i==0) {
            		while(now>0&&i*(1<<x)+(1<<x)<Max) {
            			int e=1<<x;
                		int temp=pre[Math.min(Max-1, e*i+e-1)]-pre[Math.max(e*i+(e/2)-1, 0)];
                		count+=Math.min(now, temp)*x;
                		now-=Math.min(now, temp);
                		if(now==0)
                			jud=true;
                		x++;
            		}
            		if(jud)
            			ans=Math.min(ans, count);
            		continue;
            	}
            	while(now>0&&i*(1<<x)+(1<<x)<Max) {
            		int e=1<<x;
            		int temp=pre[Math.min(Max-1, e*i+e-1)]-pre[Math.max(e*i-1, 0)];
            		count+=Math.min(now, temp)*x;
            		now-=Math.min(now, temp);
            		if(now==0)
            			jud=true;
            		x++;
            	}
            	if(!jud)
            		continue;
            	ans=Math.min(ans, count);
            	
            }
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

    }
}
