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
/*
 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));
		Scanner sc=new Scanner(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")));
		int n=sc.nextInt();
		int k=sc.nextInt();
		int[] a=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=sc.nextInt();
		}
		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;
	}
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;
 
        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }
 
        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }
 
        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }
 
        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
 
        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }
 
        public String nextLine() throws IOException {
            return br.readLine();
        }
 
        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }
 
        public boolean ready() throws IOException {
            return br.ready();
        }
    }
 
}





