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 {
    /*
     * HashMap<> map=new HashMap<>(); TreeMap<> map=new TreeMap<>();
     * map.put(p,map.getOrDefault(p,0)+1); for(Map.Entry<> mx:map.entrySet()){ int
     * v=mx.getValue(),k=mx.getKey(); }for (int i = 1; i <= 1000; i++) fac[i] =
     * fac[i - 1] * i % mod; ArrayList<Pair<Character,Integer>> l=new ArrayList<>();
     * ArrayList<> l=new ArrayList<>(); HashSet<> has=new HashSet<>();
     * PriorityQueue<Integer> pq=new PriorityQueue<>(new Comparator<Integer>(){
     * public int compare(Integer a,Integer b){ return Integer.compare(b,a); } });
     * Arrays.sort(ar,new Comparator<int[]>() { public int compare(int[] a, int[] b)
     * { return Double.compare(a[0], b[0]); } });
     */
    PrintWriter out;
    FastReader sc;
    long mod = (long) (1e9 + 7);
    long maxlong = Long.MAX_VALUE;
    long minlong = Long.MIN_VALUE;

    /******************************************************************************************
     *****************************************************************************************/
    public void sol() {
          int n=ni(),k=ni();
          int val=200001;
          int[][] ar=new int[val][2];
          int[] x=new int[n];
          for(int i=0;i<n;i++)x[i]=ni();
          sort(x);
          for(int i=0;i<n;i++){
              int p=x[i],a=0;
              ar[p][0]++;ar[p][1]+=a;
              a++;
              while(p>0){
                  p=p>>1;
                  if(ar[p][0]<k){
                    ar[p][0]++;
                    ar[p][1]+=a;
                  }
                  a++;
              }
          }int ans=Integer.MAX_VALUE;
          for(int i=0;i<val;i++){
              if(ar[i][0]>=k){
                  ans=min(ans,ar[i][1]);
              }
          }pl(ans);
    }

    public static void main(String[] args) {
        Main g = new Main();
        g.out = new PrintWriter(System.out);
        g.sc = new FastReader();
        int t = 1;
        // t=g.ni();
        while (t-- > 0)
            g.sol();
        g.out.flush();
    }

    /****************************************************************************************
     *****************************************************************************************/
    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 nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public int ni() {
        return sc.nextInt();
    }

    public long nl() {
        return sc.nextLong();
    }

    public double nd() {
        return sc.nextDouble();
    }

    public char[] rl() {
        return sc.nextLine().toCharArray();
    }

    public String rl1() {
        return sc.nextLine();
    }

    public void pl(Object s) {
        out.println(s);
    }

    public void ex() {
        out.println();
    }

    public void pr(Object s) {
        out.print(s);
    }

    public String next() {
        return sc.next();
    }

    public long abs(long x) {
        return Math.abs(x);
    }

    public int abs(int x) {
        return Math.abs(x);
    }

    public double abs(double x) {
        return Math.abs(x);
    }

    public long min(long x, long y) {
        return  Math.min(x, y);
    }

    public int min(int x, int y) {
        return  Math.min(x, y);
    }

    public double min(double x, double y) {
        return Math.min(x, y);
    }

    public long gcd(long a, long b) {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }

    public long lcm(long a, long b) {
        return (a / gcd(a, b)) * b;
    }

    void sort1(int[] a) {
        ArrayList<Integer> l = new ArrayList<>();
        for (int i : a) {
            l.add(i);
        }
        Collections.sort(l, Collections.reverseOrder());
        for (int i = 0; i < a.length; i++) {
            a[i] = l.get(i);
        }
    }

    void sort(int[] a) {
        ArrayList<Integer> l = new ArrayList<>();
        for (int i : a) {
            l.add(i);
        }
        Collections.sort(l);
        for (int i = 0; i < a.length; i++) {
            a[i] = l.get(i);
        }
    }

    void sort(long[] a) {
        ArrayList<Long> l = new ArrayList<>();
        for (long i : a) {
            l.add(i);
        }
        Collections.sort(l);
        for (int i = 0; i < a.length; i++) {
            a[i] = l.get(i);
        }
    }

    void sort1(long[] a) {
        ArrayList<Long> l = new ArrayList<>();
        for (long i : a) {
            l.add(i);
        }
        Collections.sort(l, Collections.reverseOrder());
        for (int i = 0; i < a.length; i++) {
            a[i] = l.get(i);
        }
    }

    void sort(double[] a) {
        ArrayList<Double> l = new ArrayList<>();
        for (double i : a) {
            l.add(i);
        }
        Collections.sort(l);
        for (int i = 0; i < a.length; i++) {
            a[i] = l.get(i);
        }
    }

    long pow(long a, long b) {
        if (b == 0) {
            return 1;
        }
        long p = pow(a, b / 2);
        if (b % 2 == 0)
            return (p * p);
        else
            return ((p * p) * a);
    }

    int swap(int a, int b) {
        return a;
    }

    long swap(long a, long b) {
        return a;
    }

    double swap(double a, double b) {
        return a;
    }

    boolean isPowerOfTwo(int x) {
        return x != 0 && ((x & (x - 1)) == 0);
    }

    boolean isPowerOfTwo(long x) {
        return x != 0 && ((x & (x - 1)) == 0);
    }

    public long max(long x, long y) {
        return  Math.max(x, y);
    }

    public int max(int x, int y) {
        return  Math.max(x, y);
    }

    public double max(double x, double y) {
        return Math.max(x, y);
    }

    long sqrt(long x) {
        return (long) Math.sqrt(x);
    }

    int sqrt(int x) {
        return (int) Math.sqrt(x);
    }

    void input(int[] ar, int n) {
        for (int i = 0; i < n; i++)
            ar[i] = ni();
    }

    void input(long[] ar, int n) {
        for (int i = 0; i < n; i++)
            ar[i] = nl();
    }

    void fill(int[] ar, int k) {
        Arrays.fill(ar, k);
    }

    void yes() {
        pl("YES");
    }

    void no() {
        pl("NO");
    }

    long[] sieve(int n) {
        long[] k = new long[n + 1];
        boolean[] pr = new boolean[n + 1];
        for (int i = 1; i <= n; i++) {
            k[i] = i;
            pr[i] = true;
        }
        for (int i = 2; i <= n; i++) {
            if (pr[i]) {
                for (int j = i + i; j <= n; j += i) {
                    pr[j] = false;
                    if (k[j] == j) {
                        k[j] = i;
                    }
                }
            }
        }
        return k;
    }

    int strSmall(int[] arr, int target) {
        int start = 0, end = arr.length - 1;
        int ans = -1;
        while (start <= end) {
            int mid = (start + end) / 2;
            if (arr[mid] >= target) {
                end = mid - 1;
            } else {
                ans = mid;
                start = mid + 1;
            }
        }
        return ans;
    }

    int strSmall(ArrayList<Integer> arr, int target) {
        int start = 0, end = arr.size() - 1;
        int ans = -1;
        while (start <= end) {
            int mid = (start + end) / 2;
            if (arr.get(mid) > target) {
                start = mid + 1;
                ans = start;
            } else {
                end = mid - 1;
            }
        }
        return ans;
    }

    long mMultiplication(long a, long b) {
        long res = 0;
        a %= mod;

        while (b > 0) {
            if ((b & 1) > 0) {
                res = (res + a) % mod;
            }
            a = (2 * a) % mod;

            b >>= 1;
        }
        return res;
    }

    long nCr(int n, int r, long p) {

        if (n < r)
            return 0;
        if (r == 0)
            return 1;
        long[] fac = new long[n + 1];
        fac[0] = 1;

        for (int i = 1; i <= n; i++)
            fac[i] = fac[i - 1] * i % p;
        return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p;
    }

    long power(long x, long y, long p) {
        long res = 1;
        x = x % p;

        while (y > 0) {
            if (y % 2 == 1)
                res = (res * x) % p;
            y = y >> 1;
            x = (x * x) % p;
        }

        return res;
    }

    long modInverse(long n, long p) {
        return power(n, p - 2, p);
    }

    public static class Pair implements Comparable<Pair> {
        long first;
        long second;

        public Pair(long x, long y) {
            this.first = x;
            this.second = y;
        }public int hashCode(){
              return this.hashCode();
        }

        public int compareTo(Pair other) {
            if (this.first == other.first) {
                return Long.compare(this.second, other.second);
            }
            return Long.compare(this.first, other.first);
        }

        public boolean equals(Object o) {
  
        // If the object is compared with itself then return true  
        if (o == this) {
            return true;
        }
        /* Check if o is an instance of Complex or not
          "null instanceof [type]" also returns false */
        if (!(o instanceof Pair)) {
            return false;
        }
          
        // typecast o to Complex so that we can compare data members 
        Pair c = (Pair) o;
          
        // Compare the data members and return accordingly 
        return Long.compare(first, c.first) == 0
                && Long.compare(second, c.second) == 0;
    }

}
}