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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.TreeMap;
import java.util.Map;
import java.util.Map.Entry;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author sumit
 */
public class Main {
      public static void main(String[] args) {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            InputReader in = new InputReader(inputStream);
            OutputWriter out = new OutputWriter(outputStream);
            FMakeKEqual solver = new FMakeKEqual();
            solver.solve(1, in, out);
            out.close();
      }

      static class FMakeKEqual {
            public void solve(int testNumber, InputReader in, OutputWriter out) {
                  int n = in.nextInt();
                  int k = in.nextInt();

                  int arr[] = in.nextIntArray(n);
                  TreeMap<Integer, Integer> map = new TreeMap();
                  long sum = 0;
                  for (int i = 0; i < n; i++) {
                        map.putIfAbsent(arr[i], 0);
                        map.put(arr[i], map.get(arr[i]) + 1);
                        sum += arr[i];
                  }


                  Pair left[] = new Pair[map.size()];
                  Pair right[] = new Pair[map.size()];
                  int index = 0;
                  for (Map.Entry<Integer, Integer> et : map.entrySet()) {
                        if (et.getValue() >= k) {
                              out.printLine("0");
                              return;
                        }
                        if (index > 0) {
                              left[index] = new Pair(et.getKey(), et.getValue() + left[index - 1].countSum, 1L * et.getKey() * et.getValue() + left[index - 1].sum);
                              right[index] = new Pair(et.getKey(), n - left[index - 1].countSum, sum - left[index - 1].sum);
                        } else {
                              left[index] = new Pair(et.getKey(), et.getValue(), 1L * et.getKey() * et.getValue());
                              right[index] = new Pair(et.getKey(), n, sum);
                        }
                        index++;
                  }
                  int sz = map.size();
                  long ans = Long.MAX_VALUE;
                  for (int i = 0; i < sz; i++) {
                        long ll = 0;
                        int vCrl = 0;
                        if (i > 0) {
                              ll = 1L * left[i - 1].countSum * (left[i].val - 1) - left[i - 1].sum;
                              vCrl = left[i - 1].countSum;
                        }
                        long rr = 0;
                        int vCrr = 0;
                        if (i < sz - 1) {
                              rr = right[i + 1].sum - 1L * right[i + 1].countSum * (right[i].val + 1);
                              vCrr = right[i + 1].countSum;
                        }

                        if (vCrl >= k - map.get(left[i].val)) {
                              ans = Math.min(ans, (ll + k - map.get(left[i].val)));
                        }
                        if (vCrr >= k - map.get(right[i].val)) {
                              ans = Math.min(ans, (rr + k - map.get(right[i].val)));
                        }
                        ans = Math.min(ans, rr + ll + k - map.get(right[i].val));
                  }
                  out.printLine(ans);
            }

            class Pair {
                  int val;
                  int countSum;
                  long sum;

                  Pair(int val, int countSum, long sum) {
                        this.val = val;
                        this.countSum = countSum;
                        this.sum = sum;
                  }

            }

      }

      static class OutputWriter {
            private final PrintWriter writer;

            public OutputWriter(OutputStream outputStream) {
                  writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
            }

            public OutputWriter(Writer writer) {
                  this.writer = new PrintWriter(writer);
            }

            public void print(Object... objects) {
                  for (int i = 0; i < objects.length; i++) {
                        if (i != 0) {
                              writer.print(' ');
                        }
                        writer.print(objects[i]);
                  }
            }

            public void printLine(Object... objects) {
                  print(objects);
                  writer.println();
            }

            public void close() {
                  writer.close();
            }

            public void printLine(long i) {
                  writer.println(i);
            }

      }

      static class InputReader {
            private InputStream stream;
            private byte[] buf = new byte[1024];
            private int curChar;
            private int numChars;

            public InputReader(InputStream stream) {
                  this.stream = stream;
            }

            public int read() {
                  if (numChars == -1)
                        throw new InputMismatchException();

                  if (curChar >= numChars) {
                        curChar = 0;
                        try {
                              numChars = stream.read(buf);
                        } catch (IOException e) {
                              throw new InputMismatchException();
                        }
                        if (numChars <= 0)
                              return -1;
                  }

                  return buf[curChar++];
            }

            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 & 15;

                        c = read();
                  } while (!isSpaceChar(c));

                  return res * sgn;
            }

            public int[] nextIntArray(int arraySize) {
                  int array[] = new int[arraySize];

                  for (int i = 0; i < arraySize; i++)
                        array[i] = nextInt();

                  return array;
            }

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

      }
}