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

//package cf;
import java.io.*;
import java.util.*;
import java.util.jar.JarOutputStream;

public class T_class {
    static int p=1000000007;
    static int max=(int)1e5;
    static List<Integer> l1=new ArrayList<>();
    static boolean prime[]=new boolean[max];
    static long fact[]=new long[3_000_00];
    static class  pr_int
    {
        int first;
        int second;
        public pr_int(int first, int second) {
            this.first = first;
            this.second = second;
        }
    }
    static  long anss=0;
    public static void main(String[] args) throws Exception {
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512);
        FastReader sc = new FastReader();
        int t =1;//sc.nextInt();//sc.nextInt();
        StringBuilder sb2 = new StringBuilder();
        int t2 = t;
        while (t-- > 0) {
            int n=sc.nextInt();
            int k=sc.nextInt();
            long ar[]=new long[n+1];
            long pre[]=new long[n+1];
            long suf[]=new long[n+2];
            for(int i=1;i<=n;i++)
                ar[i]=sc.nextLong();
            ruffle_sort(ar);
            Arrays.sort(ar);
            for(int i=1;i<n;i++)
            {
                pre[i]=pre[i-1]+ar[i];
            }
            for(int i=n;i>=1;i--)
            {
                suf[i]=suf[i+1]+ar[i];
            }
            long ans=Long.MAX_VALUE;
            for(int i=1;i<=n;i++)
            {
                if(ar[i]==ar[i-1])
                continue;
                int r=i;
                while(r<=n&&ar[i]==ar[r])
                r++;
                r--;
                int d=k-(r-i+1);
                long c1=1l*(i-1)*1l*(ar[i]-1)-pre[i-1];
                long c2=suf[r+1]-1l*(n-r)*1l*(ar[r]+1);
                if(d<=0)
                {
                    ans=0;
                    break;
                }
                if(i-1>=d)
                    ans=Math.min(ans,c1+d);
                if(n-r>=d)
                    ans=Math.min(ans,c2+d);
           
           
           
                    ans=Math.min(ans,c1+c2+d);
            }
            System.out.println(ans);
        }

        System.out.println(sb2.toString());
        out.flush();

    }

    private static void addto(PriorityQueue<pr_int> p1, PriorityQueue<pr_int> p2, pr_int cur1) {
        if(cur1.second==0)
            return;
        if(cur1.second>=2)
        p2.add(cur1);
    else
        p1.add(cur1);
    }

    public static  boolean isp(int n)
    {
        if(n==2||n==3||n==5||n==7||n==11||n==13||n==17)
        {
            return true;
        }
        return false;
    }
    private static String move(int[] i, String cur) {
        char ar[]=cur.toCharArray();
        //  System.out.println(cur);
        int sum=(ar[i[0]]-'0')+(ar[i[1]]-'0');
        if(isp(sum))
        {
            char t=ar[i[0]];
            ar[i[0]]=ar[i[1]];
            ar[i[1]]=t;
        }
        //System.out.println(String.valueOf(ar));
        return String.valueOf(ar);
    }

    static long lcm(long a,long b)
    {
        return  a*b/gcd(a,b);
    }
    static boolean done=false;
    static long ret;
    public  static long tolong(char ar[])
    {
        long ans=0;
        for(char i:ar)
            ans=ans*10+ (i-'0');

        return ans;
    }
    public  static  void recur(char ar[],int n,int cur,long lcm,boolean con)
    {
        if(cur==n)
        {
            System.out.println(tolong(ar)+" "+lcm);
            done=tolong(ar)%lcm==0;
            if(done)
                ret=tolong(ar);
            return;
        }
        int lst=ar[cur]-'0';
        for(int i=con?ar[cur]-'0':0;i<=9;i++)
        {
            char prev=ar[cur];
            ar[cur]=(char) (i+'0');
            recur(ar, n, cur + 1, i==0?lcm:lcm(i,lcm),lst==i);
            ar[cur]=prev;
            if(done)
                return ;
        }
    }
    static long ansa(long l,long r,long s,long ss,int n,int ar[])
    {

        while(l<=r)
        {
            long mid=(l+r)/2;
            long tot=0;
            for(int i=0;i<n;i++)
            {
                tot+=Math.abs(ar[i]-mid);
            }

            if(tot*2<=s)
            {
                // System.out.println(s+" - "+(mid*n)+" <= "+ss);
                return mid;
            }
            else if(tot*2>s)
            {
                r=mid-1;
            }
            else
            {
                l=mid+1;
            }
        }
        return 1;
    }
    static void ruffle_sort(long[] a) {
        //shandom_ruffle
        Random r=new Random();
        int n=a.length;
        for (int i=0; i<n; i++) {
            int oi=Math.abs(r.nextInt(i+1));
            long temp=a[i];
            a[i]=a[oi];
            a[oi]=temp;
        }

        //sort
        Arrays.sort(a);
    }
    static void ruffle_sort(int[] a) {
        //shandom_ruffle
        Random r=new Random();
        int n=a.length;
        for (int i=0; i<n; i++) {
            int oi=Math.abs(r.nextInt(i+1));
            int temp=a[i];
            a[i]=a[oi];
            a[oi]=temp;
        }

        //sort
        Arrays.sort(a);
    }
    static long mod=(long) 1e9+7;
    private static long nC2(long n) {
        return n*(n-1)/2;
    }
    static long mul(long a, long b) {
        return a*b%mod;
    }

    static long add(long a, long b) {
        return (a+b)%mod;
    }
    static void precomp() {
        fact[0]=1;
        for (int i=1; i<fact.length; i++) fact[i]=mul(fact[i-1], i);
    }
    static long modInv(long x) {
        return pow(x, mod-2,mod);
    }
    static long nCk(int n, int k) {
        return mul(fact[n], mul(modInv(fact[k]), modInv(fact[n-k])));
    }


    private static List<Long> getdivisors(long n) {
        List<Long> l1=new ArrayList<>();
        for(long i=1;i<=Math.sqrt(n);i++)
        {
            if(n%i==0){
                l1.add(i);
                if(n/i!=i)
                    l1.add(n/i);
            }
        }
        // System.out.println(l1);
        Collections.sort(l1);
        return l1;
    }

    private static int count(int k, int l, String cur) {
        char ar[]=cur.toCharArray();
        int c=0;
        for(int i=k;i<=l;i++)
        {
            if(i=='1')
                c++;
        }
        return c;
    }

    private static String revese(String substring) {
        StringBuilder sb=new StringBuilder();
        sb.append(substring);
        sb=sb.reverse();
        return sb.toString();
    }


    static  int ht[]=new int[max];
    static class BIT {
        long[] tree;
        public BIT(int size) {
            tree = new long[size + 1];
        }
        public long sum(int i) {
            long ans = 0;
            while (i > 0) {
                ans += tree[i];
                i -= i & -i;
            }
            return ans;
        }

        public long query(int i, int j) {
            return sum(j) - sum(i - 1);
        }

        public void add(int i, long val) {
            while (i < tree.length) {
                tree[i] += val;
                i += i & -i;
            }
        }

        public void set(int i, long val) {
            add(i, val - query(i, i));
        }
    }
    public static long pow(long a,long b,long m)
    {
        long r=1;
        while(b!=1)
        {
            if(b%2!=0)
                r=(r*a)%m;
            b=b>>1;
            a=(a*a)%m;
        }
        return (r*a)%m;
    }
    public static long gcd(long a,long b)
    {
        if(b>a)
        {
            a=a^b;
            b=a^b;
            a=a^b;
        }
        if(b==0)
            return a;
        return gcd(b,a%b);
    }
    public static void extgcd(long a,long b)
    {/*
            if(a==0)
            {
                x=0;
                y=1;
                d=b;
                // return ;
            }
            else
            {

                extgcd(b%a,a);

                long t=y;
                y=x;
                x=t-(b/a)*x;
            }*/
    }
    static  Set<Integer > used=new HashSet<>();
    public static void dfs(List<Integer>[] adj, int u, int p, boolean[] vis,long ind[],long n)
    {
        // anss-=((ind[u]-1)*(ind[u]-2))/2>0&&!used.contains(u)?((ind[u]-1)*(ind[u]-2))/2:0;

        if(((ind[u]-1)*(ind[u]-2))/2>0)
        {
            //   System.out.println(u+" -- "+((ind[u]-1)*(ind[u]))/2);
            //   used.add(u);
        }
        vis[u]=true;
        int c=0;
        for(int v:adj[u])
        {
            if(v!=p&&vis[v])
            {
                //   System.out.println(u+" c--c"+v+" "+((ind[v]-1)*(ind[v]))/2);
                if(((ind[v]-1)*(ind[v]-2))/2>0) {
                    anss -= ((ind[v] - 1) * (ind[v] - 2)) / 2 > 0 && !used.contains(v) ? ((ind[v] - 1) * (ind[v] - 2)) / 2 : 0;
                    used.add(v);
                }
                if(((ind[u]-1)*(ind[u]-2))/2>0) {
                    anss -= ((ind[u] - 1) * (ind[u] - 2)) / 2 > 0 && !used.contains(u) ? ((ind[u] - 1) * (ind[u] - 2)) / 2 : 0;
                    used.add(u);
                }
                continue;
            }
            if(!vis[v])
            {
                c++;
                dfs(adj,v,u, vis,ind,n+1);
            }
        }
        if(c==0)
        {
            anss+=(n)*(n+1l)/2;
        }
        vis[u]=false;
    }
    public static void seive()
    {
        for(int i=0;i<max;i++)
            prime[i] = true;

        for(int p = 2; p*p <=max; p++)
        {
            // If prime[p] is not changed, then it is a prime
            if(prime[p] == true)
            {
                // Update all multiples of p
                for(int i = p*p; i <=max; i += p)
                    prime[i] = false;
            }
        }

        // Print all prime numbers
        for(int i = 2; i <= max; i++)
        {
            if(prime[i] == true)
            {
                l1.add(i);
            }
        }
    }
    public static boolean union(int a, int b, int p[], int r[]){
        // add your code here
        int pa=find(a,p,r);
        int pb=find(b,p,r);
        if(pa==pb)
            return true;
        if(pa!=pb)
        {
            if(r[pa]<r[pb])
            {
                p[pa]=pb;
            }
            else if(r[pa]>r[pb])
            {
                p[pb]=pa;
            }
            else
            {
                p[pa]=pb;
                r[pb]++;
            }
        }
        return false;
    }
    public static int find(int x,int p[],int r[])
    {
        if(p[x]==x)
            return x;
        p[x]=find(p[x],p,r);
        return p[x];
    }
    public static int binary_Search_upper(int[] ar,int l, int x)
    {
        int res=-1;
        int r=ar.length-1;
        while(l<=r)
        {
            int mid=(l+r)>>1;
            if(ar[mid]<=x)
            {
                res=mid;
                l=mid+1;
            }
            else if(ar[mid]>x)
            {
                //res=mid;
                r=mid-1;
            }
        }
        return res;
    }
    public static int binary_Search_lower(int[] ar, int x)
    {
        int res=ar.length;
        int l=0;int r=ar.length-1;
        while(l<=r)
        {
            int mid=(l+r)>>1;
            if(ar[mid]>=x)
            {
                res=mid;
                r=mid-1;
            }
            else
            {
                l=mid+1;
            }
        }
        return res;
    }
    int bit[]=new int[(int)1e6];
    public void update(int n,int val,int i)
    {
        i++;
        while(i<n)
        {
            bit[i]+=val;
            i+=(i)&(-i);
        }

    }
    public long query(int n,int i)
    {
        i++;
        long sum=0;
        while(i>0)
        {
            sum+=bit[i];
            i-=(i)&(-i);
        }
        return sum;
    }


    ///////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////////////////
    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;
        }
    }


}
