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.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Collections;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Puneet    //FastRead class is taken from different online Sources
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastInput in = new FastInput(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD2 solver = new TaskD2();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD2 {
        HashMap<Integer, ArrayList<Integer>> map = new HashMap<>();

        public void solve(int testNumber, FastInput in, PrintWriter out) {
            int n = in.ni(), k = in.ni();
            int[] arr = in.intarr(n);

            for (int i = 0; i < n; i++) {
                int num = arr[i];
                int step = 0;
                put(step, num);
                while (num > 0) {
                    num /= 2;
                    step++;
                    put(step, num);
                }
            }

            for (int i = 0; i < n; i++) {
                if (map.containsKey(i)) {
                    Collections.sort(map.get(i));
                }
            }
            int total = Integer.MAX_VALUE;

            for (int i = 0; i <= 2 * 100000; i++) {
                int temp = 0;
                if (map.containsKey(i) && map.get(i).size() >= k) {
                    for (int i1 = 0; i1 < k; i1++) {
                        temp += map.get(i).get(i1);
//                    if(i==2){
//                        out.print(temp+" == ");
//                    }
                    }

//                out.println(i+" -- ");
//
//                for(int i1 = 0;i1<map.get(i).size();i1++){
//                    out.print(map.get(i).get(i1)+" ");
//                }
//                out.println();

                    total = Math.min(total, temp);
                }
            }

            out.println(total);
        }

        void put(int step, int num) {
            if (map.containsKey(num)) {
                map.get(num).add(step);
            } else {
                map.put(num, new ArrayList<>());
                map.get(num).add(step);
            }
        }

    }

    static class FastInput {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastInput.SpaceCharFilter filter;

        public FastInput(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int ni() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int[] intarr(int n) {
            int arr[] = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = ni();
            }
            return arr;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}