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.*;
import java.lang.reflect.Array;
import java.util.*;
public class Contest1 {

    static long getlow(int x,int rem){
        long ans =0;
        int low= x-1;
        Integer ll=lower.floorKey(low);
        if (ll!=null){
            ans=lower.get(ll)+(x-1-ll)*lowec.get(ll);
            if (rem<=lowec.get(ll)){
                ans+=rem;
                rem=0;
            }
            else{
                rem-=lowec.get(ll);
                ans+=lowec.get(ll);
            }
        }
        if (rem!=0)
            ans+=gethi(x,rem);
        return ans;
    }
    static long gethi(int x,int rem){
        long ans=0;
        int hi = x+1;
        Integer ll=upper.ceilingKey(hi);
        if (ll!=null){
            ans=upper.get(ll)+(ll-x-1)*upperc.get(ll);
            if (rem<=upperc.get(ll)){
                ans+=rem;
                rem=0;
            }
            else{
                rem-=upperc.get(ll);
                ans+=upperc.get(ll);
            }
        }
        if (rem!=0)
            ans+=getlow(x,rem);
        return ans;
    }
    static TreeMap<Integer,Long>lower,upper,lowec,upperc;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int k = sc.nextInt();
        Integer[]a = new Integer[n];
        TreeMap<Integer,Integer>count = new TreeMap<>(),cout2= new TreeMap<>(Collections.reverseOrder());
        for (int i =0;i<n;i++){
            a[i]=sc.nextInt();
            count.put(a[i],count.getOrDefault(a[i],0)+1);
            cout2.put(a[i],count.get(a[i]));
        }
        lower = new TreeMap<>();
        upper= new TreeMap<>();
        upperc= new TreeMap<>();
        lowec= new TreeMap<>();
        Arrays.sort(a);
        int pre=-1;
        int c=0;
        for (int x:count.keySet()){
            if (pre==-1)
                lower.put(x,0l);
            else {
                lower.put(x,1l*c*(x-pre)+lower.get(pre));
            }
            pre=x;
            c+=count.get(pre);
            lowec.put(pre,1l*c);
        }
        pre=-1;
        c=0;
        for (int x:cout2.keySet()){
            if (pre==-1)
                upper.put(x,0l);
            else {
                upper.put(x,1l*c*(pre-x)+upper.get(pre));
            }
            pre=x;
            c+=count.get(pre);
            upperc.put(pre,1l*c);
        }
        long ans=(long)1e18;
        for (int i =0;i<n;i++){
            if (i==n-1||a[i]!=a[i+1]){
                if (count.get(a[i])>=k){
                    ans=0;
                    break;
                }
                int cc= count.get(a[i]);
                long a2=Math.min(getlow(a[i],k-cc),gethi(a[i],k-cc));
                ans=Math.min(ans,a2);
            }
        }
        pw.println(ans);
        pw.flush();
    }
    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();
        }
    }

}