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.io.*;
import java.lang.*;
import java.math.*;
import java.util.Map.*;
public class codeforces {
	static PrintWriter pw=new PrintWriter(System.out);
	 
	public static void main(String [] args) throws Exception {
		
		Scanner sc=new Scanner(System.in);
		int x=sc.nextInt(); int k=sc.nextInt();
		long min=(long)2e10;
		int [] arr=sc.nextIntArraySorted(x);
		//pw.println(Arrays.toString(arr));
		PriorityQueue<Integer> q=new PriorityQueue<>();
		for (int l =0;l<=2*100000;l++){
		q.clear();
		for(int i=0;i<x;i++) {
			int sum=0;
			int z=arr[i];
			boolean f=true;
			while(z!=l &&f) {
				if(z==0) {f=!f; break;}
				sum++; z>>=1;
			}
			if(f) q.add(sum);
		}
		 if(q.size()>=k) {
			 int sum=0;
			 for(int j=0;j<k;j++) sum+=q.poll();
			 min=Math.min(min, sum);
		 }
		}
		pw.println(min);
		pw.flush(); 
		pw.close();
	}
	static class pair implements Comparable<pair>{
		int x, y;
		public pair(int x,int y) {this.x=x; this.y=y;}
		public int compareTo(pair p) {
			return x-p.x;
		}
		public String toString() {return x+" "+y;}
	}
	   static class Scanner {
			StringTokenizer st;
			BufferedReader br;
	 
			public Scanner(InputStream system) {
				br = new BufferedReader(new InputStreamReader(system));
			}
	 
			public Scanner(String file) throws Exception {
				br = new BufferedReader(new FileReader(file));
			}
	 
			public String next() throws IOException {
				while (st == null || !st.hasMoreTokens())
					st = new StringTokenizer(br.readLine());
				return st.nextToken();
			}
			public String nextLine() throws IOException {
				return br.readLine();
			}
	 
			public int nextInt() throws IOException {
				return Integer.parseInt(next());
			}
	 
			public double nextDouble() throws IOException {
				String x = next();
				StringBuilder sb = new StringBuilder("0");
				double res = 0, f = 1;
				boolean dec = false, neg = false;
				int start = 0;
				if (x.charAt(0) == '-') {
					neg = true;
					start++;
				}
				for (int i = start; i < x.length(); i++)
					if (x.charAt(i) == '.') {
						res = Long.parseLong(sb.toString());
						sb = new StringBuilder("0");
						dec = true;
					} else {
						sb.append(x.charAt(i));
						if (dec)
							f *= 10;
					}
				res += Long.parseLong(sb.toString()) / f;
				return res * (neg ? -1 : 1);
			}
	 
			public char nextChar() throws IOException {
				return next().charAt(0);
			}
	 
			public Long nextLong() throws IOException {
				return Long.parseLong(next());
			}
	 
			public boolean ready() throws IOException {
				return br.ready();
			}
			public char [] nextCharArray() throws IOException {
				return next().toCharArray();
			}
			public int[] nextIntArray(int n) throws IOException {
	            int[] a = new int[n];
	            for (int i = 0; i < n; i++)
	                a[i] = nextInt();
	            return a;
	        }
	        public long[] nextLongArray(int n) throws IOException {
	            long[] a = new long[n];
	            for (int i = 0; i < n; i++)
	                a[i] = nextLong();
	            return a;
	        }
	        public HashMap<Integer, Integer> nextHashMap(int n) throws IOException{
	        	HashMap<Integer, Integer> map =new HashMap<>();
	        	for(int i=0;i<n;i++) {
	        		int x=nextInt();
	        		int b=map.getOrDefault(x, 0);
	        		map.put(x, b+1);
	        	}
	        	return map;
	        }
	        public TreeMap<Integer, Integer> nextTreeMap(int n) throws IOException{
	        	TreeMap<Integer, Integer> map =new TreeMap<>();
	        	for(int i=0;i<n;i++) {
	        		int x=nextInt();
	        		int b=map.getOrDefault(x, 0);
	        		map.put(x, b+1);
	        	}
	        	return map;
	        }
	        public HashSet<Integer> nextHashSet (int n) throws IOException{
	        	HashSet<Integer> set=new HashSet<>();
	        	for(int i=0;i<n;i++) set.add(nextInt());
	        	return set;
	        }
	        public TreeSet<Integer> nextTreeSet (int n) throws IOException{
	        	TreeSet<Integer> set=new TreeSet<>();
	        	for(int i=0;i<n;i++) set.add(nextInt());
	        	return set;
	        }
	        public long[] nextLongArraySorted(int n) throws IOException {
	        	long [] arr=nextLongArray(n);
	        	Arrays.parallelSort(arr);
	            return arr;
	        }
	        public int [] nextIntArraySorted(int n) throws IOException{
	        	int [] arr=nextIntArray(n);
	        	Arrays.parallelSort(arr);
	        	return arr;
	        }
		    public void waitForInput() throws InterruptedException {
				Thread.sleep(3000);
			}
		}
	}