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.*;


public class Main {
    
    static class Reader 
    { 
        final private int BUFFER_SIZE = 1 << 16; 
        private DataInputStream din; 
        private byte[] buffer; 
        private int bufferPointer, bytesRead; 
  
        public Reader() 
        { 
            din = new DataInputStream(System.in); 
            buffer = new byte[BUFFER_SIZE]; 
            bufferPointer = bytesRead = 0; 
        } 
  
        public Reader(String file_name) throws IOException 
        { 
            din = new DataInputStream(new FileInputStream(file_name)); 
            buffer = new byte[BUFFER_SIZE]; 
            bufferPointer = bytesRead = 0; 
        } 
  
        public String readLine() throws IOException 
        { 
            byte[] buf = new byte[1000001]; // line length 
            int cnt = 0, c; 
            while ((c = read()) != -1) 
            { 
                if (c == '\n') 
                    break; 
                buf[cnt++] = (byte) c; 
            } 
            return new String(buf, 0, cnt); 
        } 
  
        public int nextInt() throws IOException 
        { 
            int ret = 0; 
            byte c = read(); 
            while (c <= ' ') 
                c = read(); 
            boolean neg = (c == '-'); 
            if (neg) 
                c = read(); 
            do
            { 
                ret = ret * 10 + c - '0'; 
            }  while ((c = read()) >= '0' && c <= '9'); 
  
            if (neg) 
                return -ret; 
            return ret; 
        } 
  
        public long nextLong() throws IOException 
        { 
            long ret = 0; 
            byte c = read(); 
            while (c <= ' ') 
                c = read(); 
            boolean neg = (c == '-'); 
            if (neg) 
                c = read(); 
            do { 
                ret = ret * 10 + c - '0'; 
            } 
            while ((c = read()) >= '0' && c <= '9'); 
            if (neg) 
                return -ret; 
            return ret; 
        } 
  
        public double nextDouble() throws IOException 
        { 
            double ret = 0, div = 1; 
            byte c = read(); 
            while (c <= ' ') 
                c = read(); 
            boolean neg = (c == '-'); 
            if (neg) 
                c = read(); 
  
            do { 
                ret = ret * 10 + c - '0'; 
            } 
            while ((c = read()) >= '0' && c <= '9'); 
  
            if (c == '.') 
            { 
                while ((c = read()) >= '0' && c <= '9') 
                { 
                    ret += (c - '0') / (div *= 10); 
                } 
            } 
  
            if (neg) 
                return -ret; 
            return ret; 
        } 
  
        private void fillBuffer() throws IOException 
        { 
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); 
            if (bytesRead == -1) 
                buffer[0] = -1; 
        } 
  
        private byte read() throws IOException 
        { 
            if (bufferPointer == bytesRead) 
                fillBuffer(); 
            return buffer[bufferPointer++]; 
        } 
  
        public void close() throws IOException 
        { 
            if (din == null) 
                return; 
            din.close(); 
        } 
    } 
    public static void print(int[] arr){
            for(int i = 0 ;i<arr.length;i++){
                System.out.print((arr[i])+" ");
            }
            System.out.println("");
    }
    public static void printlist(ArrayList<Integer> arr){
            for(int i = 0 ;i<arr.size();i++){
                System.out.print((arr.get(i)+1)+" ");
            }
            System.out.println("");
    }
 
    
    public static void main(String[] args) throws IOException {
            Reader sc = new Reader();
            int n = sc.nextInt();
            int k = sc.nextInt();
            int[] arr = new int[n];
            int max = 0;
            for(int i = 0;i<n;i++){
                arr[i] = sc.nextInt();
                max = Math.max(max,arr[i]);
            }
            Arrays.sort(arr);
            ArrayList<ArrayList<Integer>> cost = new ArrayList<>();
            for(int i = 0;i<=max;i++){
                ArrayList<Integer> temp = new ArrayList<>();
                cost.add(temp);
            }
            for(int i = 0;i<n;i++){
                int val = arr[i];
                int opt = 0;
                while(val>0){
                    if(cost.get(val).size()==0){
                        cost.get(val).add(opt);
                    }else{
                        cost.get(val).add(cost.get(val).get(cost.get(val).size()-1)+opt);
                    }
                    opt++;
                    val/=2;
                }
                if(cost.get(0).size()==0){
                    cost.get(0).add(opt);
                }else{
                    int last = cost.get(0).get(cost.get(0).size()-1)+opt;
                    cost.get(0).add(last);
                }
            }
            int min = Integer.MAX_VALUE;
            for(int i = max;i>=0;i--){
                if(cost.get(i).size()>=k){
                    min = Math.min(min,cost.get(i).get(k-1));
                }
            }
            System.out.println(min);
    }
}