import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math;
int read() { return readln.chomp.to!int; }
int[] reads() { return readln.split.to!(int[]); }


void main() {
    int n, k; readf("%d %d\n", &n,&k);
    int[] x = reads();
    int x0 = x[0];
    long[] a = x.map!(i => i - x0).array.to!(long[]);

    long ans = long.max;
    foreach (i; 0..n-k+1) {
        long len = a[k - 1 + i] - a[i] + min(x[i], x[k - 1 + i]).abs;
        ans = min(ans, len);
    }
    writeln(ans);
}
