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.util.*;
import java.lang.*;
import java.lang.reflect.Array;
import java.io.*;
import java.math.*;
import java.text.DecimalFormat;
public class Prac{   
 
  
  
    static class InputReader {
 
		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
 
		public InputReader(InputStream st) {
			this.stream = st;
		}
 
		public int read() {
			if (snumChars == -1)
	 			throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 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 {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
 
		public long nl() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
 
		public int[] nia(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = ni();
			}
			return a;
		}
 
		public String rs() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}
 
		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}
 
		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
 
		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
 
	}
    static PrintWriter w = new PrintWriter(System.out);
  
 
   
    public static void main(String[] args) throws IOException {   
        InputReader sc=new InputReader(System.in); 
        int n=sc.ni();
        int k=sc.ni();
        int arr[]=new int[n];
        for(int i=0;i<n;i++){
            arr[i]=sc.ni();
        }
        long min=Integer.MAX_VALUE;
        Arrays.sort(arr);
        for(int i=0;i<n;i++){
            Set<Integer> set=new HashSet<Integer>();
            set.add(arr[i]);
            int val=arr[i];
            while(val>0){
                val/=2;
                set.add(val);
            }
            Iterator itr=set.iterator();
            while(itr.hasNext()){
                long count=0;
                int t=k;
                int num=(int)itr.next();
                for(int j=0;j<n;j++){
                    if(arr[j]<num){
                        continue;
                    }
                    else{
                        int a=arr[j];
                        long temp=0;
                        while(a>num){
                            a=a/2;
                            temp++;
                        }
                        if(a==num){
                            count+=temp;
                            t--;
                        }
                    }
                    if(t==0){
                        break;
                    }
                }
                if(t==0)
                    min=Math.min(count,min);
        }
//            count=0;
//            t=k;
//            for(int j=0;j<n;j++){
//                int num=arr[i]-1;
//                if(arr[j]<arr[i]){
//                    continue;
//                }
//                else{
//                    int a=arr[j];
//                    long temp=0;
//                    while(a>num){
//                        a=a/2;
//                        temp++;
//                    }
//                    if(a==num){
//                        count+=temp;
//                        t--;
//                    }
//                }
//                if(t==0){
//                    break;
//                }
//            }
//            if(t==0)
//                min=Math.min(count,min);
        }
        w.println(min);
        w.close();
    }
}