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.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.TreeMap;

public class F {

	public static void main(String[] args) {
		new F();
	}

	public F() {
		FasterScanner sc = new FasterScanner(System.in);

		int n = sc.nextInt();
		long k = sc.nextInt();
		Long[] a = new Long[n];
		TreeMap<Long, Integer> counts = new TreeMap<Long, Integer>();
		for (int i = 0; i < n; i++) {
			a[i] = (long)sc.nextInt();
			if (!counts.containsKey(a[i])) counts.put(a[i], 0);
			counts.put(a[i], counts.get(a[i])+1);
		}
		Arrays.sort(a);
		long[] prefSum = new long[n];
		for (int i = 0; i < n; i++) {
			prefSum[i] = a[i];
			if (i > 0) {
				prefSum[i] += prefSum[i - 1];
			}
		}
		long[] suffSum = new long[n];
		for (int i = n - 1; i >= 0; i--) {
			suffSum[i] = a[i];
			if (i < (n - 1)) {
				suffSum[i] += suffSum[i + 1];
			}
		}
		long best = Long.MAX_VALUE;
		for (long i = 0; i < n; i++) {
			//if (i!= 0 && i!= (n-1) && a[i-1]==a[i] && a[i] == a[i+1]) continue;
			long val = a[(int)i];
			//k==n
			if (k==n) {
				long c = 0;
				if (i > 0) c += Math.max(0, (val*i - prefSum[(int)i-1]));
				if (i < (n-1)) c += Math.max(0, (suffSum[(int)i+1] - val*(n-((int)i+1))));
				best = Math.min(best, c);
				continue;
			}
			//first lower
			long costL = 0;
			if (i+1 >= k) {
				if (i > 0) costL += Math.max(0, (val*i - prefSum[(int)i-1] - (i+1-k)));
			} else {
				if (i > 0) costL += Math.max(0, (val*i - prefSum[(int)i-1]));
				costL += Math.max(0, (suffSum[(int)i+1] - val*(n-(i+1)) - (n-k)));
			}
			//System.out.println(val + " " + costL);
			best = Math.min(best, costL);
			//first higher
			long costH = 0;
			if ((n-i) >= k) {
				if (i < (n-1)) costH += Math.max(0, (suffSum[(int)i+1] - val*(n-(i+1)) - (n-(i+1)-(k-1))));
			} else {
				if (i < (n-1)) costH += Math.max(0, (suffSum[(int)i+1] - val*(n-(i+1))));
				costH += Math.max(0, (val*i - prefSum[(int)i-1] - (n-k)));
			}
			//System.out.println(val + " " + costH);
			best = Math.min(best, costH);
		}
		if (k == 1) best = 0;
		for (long l: counts.keySet()) {
			if (counts.get(l) >= k) best = 0;
		}
		System.out.println(best);

		sc.close();
	}
	
	class FasterScanner {
		private InputStream mIs;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FasterScanner() {
			this(System.in);
		}

		public FasterScanner(InputStream is) {
			mIs = is;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = mIs.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		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 String nextString() {
			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 long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		public void close() {
			try {
				mIs.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}