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.math.BigInteger;
import java.util.*;
import java.lang.*;
import java.io.*;

public class Solution {
    static int freq[][];
    public static void calc(int x,int val)
    {
        if(x==0)
            return;
        freq[x][val]++;
        calc(x/2,val+1);

    }
    public static void main (String[] args)throws IOException {
        //code
        FastReader in=new FastReader(System.in);
        StringBuilder sb=new StringBuilder();
        int i,j,sum,cost;
        int n=in.nextInt();
        int m=in.nextInt();
        int arr[]=new int[n];
        int ans=Integer.MAX_VALUE;
        freq=new int[200001][20];
        for(i=0;i<n;i++)
        {
            arr[i]=in.nextInt();
            calc(arr[i],0);
        }
        for(i=1;i<=200000;i++)
        {
            sum=0;
            cost=0;
            for(j=0;j<20;j++)
            {
                sum+=freq[i][j];
                cost+=j*freq[i][j];
                if(sum>=m)
                {
                    cost-=(sum-m)*j;
                    ans=Math.min(ans,cost);
                    //System.out.println(i+" "+cost+" "+sum);
                    break;
                }
            }
        }
        System.out.println(ans);


    }
}
class Node implements Comparable<Node>
{
    int val,pos;
    public Node(int val,int pos)
    {
        this.val=val;
        this.pos=pos;
    }
    public int compareTo(Node x)
    {
        if(this.val>x.val)
            return -1;
        else if(this.val<x.val)
            return 1;
        else
            return 0;
    }
}
class FastReader {

    byte[] buf = new byte[2048];
    int index, total;
    InputStream in;

    FastReader(InputStream is) {
        in = is;
    }

    int scan() throws IOException {
        if (index >= total) {
            index = 0;
            total = in.read(buf);
            if (total <= 0) {
                return -1;
            }
        }
        return buf[index++];
    }

    String next() throws IOException {
        int c;
        for (c = scan(); c <= 32; c = scan()) ;
        StringBuilder sb = new StringBuilder();
        for (; c > 32; c = scan()) {
            sb.append((char) c);
        }
        return sb.toString();
    }

    String nextLine() throws IOException {
        int c;
        for (c = scan(); c <= 32; c = scan()) ;
        StringBuilder sb = new StringBuilder();
        for (; c != 10 && c != 13; c = scan()) {
            sb.append((char) c);
        }
        return sb.toString();
    }

    char nextChar() throws IOException {
        int c;
        for (c = scan(); c <= 32; c = scan()) ;
        return (char) c;
    }

    int nextInt() throws IOException {
        int c, val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+') {
            c = scan();
        }
        for (; c >= '0' && c <= '9'; c = scan()) {
            val = (val << 3) + (val << 1) + (c & 15);
        }
        return neg ? -val : val;
    }

    long nextLong() throws IOException {
        int c;
        long val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+') {
            c = scan();
        }
        for (; c >= '0' && c <= '9'; c = scan()) {
            val = (val << 3) + (val << 1) + (c & 15);
        }
        return neg ? -val : val;
    }
}