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.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
import java.util.stream.Collectors;

public class problem4 {
    public static void main(String[] args) throws Exception{
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tokenizer = new StringTokenizer(reader.readLine());
        int n = Integer.parseInt(tokenizer.nextToken());
        int k = Integer.parseInt(tokenizer.nextToken());

        tokenizer = new StringTokenizer(reader.readLine());
        int[] arr = new int[n];
        for(int i = 0; i < n;i++){
            arr[i] = Integer.parseInt(tokenizer.nextToken());
        }

        HashMap<Integer, TreeMap<Integer,Integer>> map = new HashMap<>();
        int maxK = 0;
        for(int i = 0; i < n;i++){
            if(map.containsKey(arr[i])){
                TreeMap<Integer, Integer> treeMap = map.get(arr[i]);
                if(treeMap.containsKey(0)){
                    treeMap.put(0,treeMap.get(0)+1);
                }else{
                    treeMap.put(0,1);
                }
                maxK = Math.max(maxK,treeMap.get(0));
            }else{
                map.put(arr[i],new TreeMap<>());
                TreeMap<Integer, Integer> treeMap = map.get(arr[i]);
                treeMap.put(0,1);
                maxK = Math.max(maxK,treeMap.get(0));
            }
        }

        if(maxK >= k){
            System.out.println(0);
            return;
        }else{
            List<Integer> collect = new ArrayList<>(map.keySet());
            for(int value:collect){
                int size = map.get(value).get(0);
                int depth = 1;
                while (value > 0){
                    value = value>>1;
                    if(map.containsKey(value)){
                        TreeMap<Integer, Integer> treeMap = map.get(value);
                        if(treeMap.containsKey(depth)){
                            treeMap.put(depth,treeMap.get(depth)+size);
                        }else{
                            treeMap.put(depth,size);
                        }
                    }else{
                        map.put(value,new TreeMap<>());
                        TreeMap<Integer, Integer> treeMap = map.get(value);
                        treeMap.put(depth,size);
                    }
                    depth++;
                }
            }
        }

        HashMap<Integer, TreeMap<Integer,Integer>> map2 = new HashMap<>();
        for(Map.Entry<Integer,TreeMap<Integer,Integer>> entry:map.entrySet()){
            Integer sum = entry.getValue().values().stream().reduce((s1, s2) -> s1 + s2).orElse(0);
            if(sum >= k){
                map2.put(entry.getKey(),entry.getValue());
            }
        }
        int result = Integer.MAX_VALUE;
        for(Map.Entry<Integer,TreeMap<Integer,Integer>> entry2:map2.entrySet()){
            TreeMap<Integer, Integer> value = entry2.getValue();
            Integer key = value.firstKey();
            int elements = 0;
            int preResult = 0;
            while (elements != k){
                Integer s = value.get(key);
                if(elements+s > k){
                    int tmp = k-elements;
                    elements+=tmp;
                    preResult+=tmp*key;
                }else{
                    elements+=s;
                    preResult+=s*key;
                }
                key = value.higherKey(key);
            }
            result = Math.min(preResult,result);
        }
        System.out.println(result);

    }
}
