#include <bits/stdc++.h>
using namespace std;
int n, m;
int x[1000006];
long long test(int pos) {
  long long ret = 0LL;
  for (int le = 0, ri = 0; le < n && x[le] < pos; le = ri) {
    int Count = 0;
    while (ri < n && x[ri] < pos && Count < m) {
      ri++;
      Count++;
    }
    if (Count > 0) ret += 2LL * (pos - x[le]);
  }
  for (int ri = n - 1, le = n - 1; ri >= 0 && x[ri] > pos; ri = le) {
    int Count = 0;
    while (le >= 0 && x[le] > pos && Count < m) {
      le--;
      Count++;
    }
    if (Count > 0) ret += 2LL * (x[ri] - pos);
  }
  return ret;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", &x[i]);
  int le = x[0], ri = x[n - 1];
  while (ri - le >= 3) {
    int m1 = le + (ri - le) / 3;
    int m2 = ri - (ri - le) / 2;
    if (test(m1) > test(m2))
      le = m1;
    else
      ri = m2;
  }
  long long ans = test(le);
  for (int i = le; i <= ri; i++) {
    long long r = test(i);
    if (r < ans) ans = r;
  }
  printf("%I64d\n", ans);
  return 0;
}
