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

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

  static class FMakeKEqual {
    public final void solve(int testNumber, InputReader in, PrintWriter out) {
      int n = in.nextInt();
      int k = in.nextInt();
      int[] a = in.nextIntArrayOneBased(n);
      ArrayShuffler.shuffle(a);
      Arrays.sort(a);

      long[] pre = new long[n + 1];
      for (int i = 1; i <= n; i++) {
        pre[i] += pre[i - 1] + a[i];
      }

      long ans = Constants.INF64;
      for (int i = 1; i <= n; i++) {
        int j = i;
        while (j <= n && a[j] == a[i]) {
          ++j;
        }
        --j;

        int rest = k - (j - i + 1);
        if (rest <= 0) {
          ans = 0;
          break;
        }

        long r = n - j;
        long l = i - 1;
        long lCost = l * a[i] - pre[i - 1];
        long rCost = (pre[n] - pre[j]) - r * a[i];

        if (l >= rest) {
          ans = Math.min(ans, lCost - (l - rest));
        }
        if (r >= rest) {
          ans = Math.min(ans, rCost - (r - rest));
        }
        ans = Math.min(ans, lCost + rCost - (l + r - rest));
        i = j;
      }

      out.println(ans);
    }
  }

  static class ArrayShuffler {
    private static Random r = new Random(System.nanoTime() * 21);

    private ArrayShuffler() {
      throw new RuntimeException("DON'T");
    }

    public static int[] shuffle(int[] arr, int from, int to) {
      int n = to - from + 1;
      for (int i = from; i <= to; i += 4) {
        int p = r.nextInt(n + 1) + from;
        if (p <= to) {
          int temp = arr[i];
          arr[i] = arr[p];
          arr[p] = temp;
        }
      }
      return arr;
    }

    public static int[] shuffle(int[] arr) {
      return shuffle(arr, 0, arr.length - 1);
    }
  }

  static final class InputReader {
    private final InputStream stream;
    private final byte[] buf = new byte[1 << 16];
    private int curChar;
    private int numChars;

    public InputReader() {
      this.stream = System.in;
    }

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

    private final int read() {
      if (this.numChars == -1) {
        throw new UnknownError();
      } else {
        if (this.curChar >= this.numChars) {
          this.curChar = 0;

          try {
            this.numChars = this.stream.read(this.buf);
          } catch (IOException ex) {
            throw new InputMismatchException();
          }

          if (this.numChars <= 0) {
            return -1;
          }
        }

        return this.buf[this.curChar++];
      }
    }

    public final int nextInt() {
      int c;
      for (c = this.read(); isSpaceChar(c); c = this.read()) {}

      byte sgn = 1;
      if (c == 45) { // 45 == '-'
        sgn = -1;
        c = this.read();
      }

      int res = 0;

      while (c >= 48 && c <= 57) { // 48 == '0', 57 == '9'
        res *= 10;
        res += c - 48; // 48 == '0'
        c = this.read();
        if (isSpaceChar(c)) {
          return res * sgn;
        }
      }

      throw new InputMismatchException();
    }

    private static final boolean isSpaceChar(final int c) {
      return c == 32 || c == 10 || c == 13 || c == 9
          || c == -1; // 32 == ' ', 10 == '\n', 13 == '\r', 9 == '\t'
    }

    public final int[] nextIntArrayOneBased(final int n) {
      int[] ret = new int[n + 1];
      for (int i = 1; i <= n; i++) {
        ret[i] = nextInt();
      }
      return ret;
    }
  }

  static class Constants {
    public static final long INF64 = 0x3f3f3f3f3f3f3f3fL;
  }
}
