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.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Solution
{
    static class comp implements Comparator<A>
    {
        public int compare(A a,A b)
        {
            int temp=a.cost-b.cost;
            if(temp<0)
                return -1;
            else if(temp>0)
                return 1;
            else
                return a.temp-b.temp;
        }
    }
    static class A{
        int cost;
        int temp;
        A(int index,int count)
        {
            this.temp=index;
            this.cost=count;
        }
    }
	public static void main (String[] args)
	{
            FastReader s1 = new FastReader();
            StringBuilder sb = new StringBuilder();
            int n=s1.I();
            int k=s1.I();
            Integer ar[]=new Integer[n];
            int max=Integer.MIN_VALUE;
            for(int i=0;i<n;i++)
            {
                ar[i]=s1.I();
                max=Math.max(ar[i], max);
            }
            Arrays.sort(ar);
            ArrayList<Integer> br[]=new ArrayList[max+1];
            for(int i=0;i<=max;i++)
                br[i]=new ArrayList<Integer>();
            for(int i=0;i<n;i++)
            {
                int temp=ar[i];
                int j=0;
                while(temp>0)
                {
                    br[temp].add(j);
                    temp=temp/2;
                    j++;
                }
            }
            int ans=Integer.MAX_VALUE;
            for(int i=0;i<=max;i++)
            {
                int demo=0;
                if(br[i].size()>=k)
                {
                 //   Collections.sort(br[i]);
                    for(int l=0;l<k;l++)
                        demo+=br[i].get(l);
                    ans=Math.min(ans, demo);
                }
            }
            System.out.println(ans);
	}
        static int binary(int left,int right,int ar[],int no)
        {
             int mid=(left+right)/2;
             if(Math.abs(right-left)<=1)
             {
                 if(no>=ar[right])
                 {
                     return right+1;
                 }
                 else if(no<ar[left])
                 {
                     return left;
                 }
                 else
                 {
                      return left+1;
                 }
             }
             if(ar[mid]>no)
             {
                 right=mid-1;
                 return binary(left, right, ar, no);
             }
             else{
                 left=mid;
                 return binary(left, right, ar, no);
                         }
        }
	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(); 
        } 
  
        int I() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long L() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double D() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
    static int gcd(int a,int b)
		{
		    if(a%b==0)
		    return b;
		    return gcd(b,a%b);
		}
	static float power(float x, int y) 
    { 
        float temp; 
        if( y == 0) 
            return 1; 
        temp = power(x, y/2);  
          
        if (y%2 == 0) 
            return temp*temp; 
        else
        { 
            if(y > 0) 
                return x * temp * temp; 
            else
                return (temp * temp) / x; 
        } 
    } 
    static long pow(int a,int b)
    {
        long result=1;
        if(b==0)
        return 1;
        long x=a;
        while(b>0)
        {
            if(b%2!=0)
            result*=x;
            
            x=x*x;
            b=b/2;
        }
        return result;
    }
    
    static ArrayList<Integer> sieveOfEratosthenes(int n) 
    { 
        ArrayList<Integer> arr=new ArrayList<Integer>();
        boolean prime[] = new boolean[n+1]; 
        for(int i=2;i<n;i++) 
            prime[i] = true; 
          
        for(int p = 2; p*p <=n; p++) 
        { 
            if(prime[p] == true) 
            { 
                arr.add(p);
                for(int i = p*p; i <= n; i += p) 
                    prime[i] = false; 
            } 
        } 
        return arr;
    } 
}