import sys

import math  # noqa

import bisect  # noqa

import queue  # noqa





def input():

    return sys.stdin.readline().rstrip()





def solve(X, K):

    N = len(X)



    cumsum = [0 for _ in range(N)]

    for i in range(1, N):

        cumsum[i] = abs(X[i] - X[i - 1]) + cumsum[i - 1]



    idx_zero = bisect.bisect_left(X, 0)



    ret = 1000000005

    for i in range(0, N):

        if X[i] >= 0:

            break

        res = -X[i]

        k = idx_zero - i

        if (k < K) and (idx_zero + K - k - 1 < N):

            res += cumsum[idx_zero + K - k - 1] - cumsum[i]

            ret = min(ret, res)



    return ret





if __name__ == '__main__':

    N, K = list(map(int, input().split()))

    X = list(map(int, input().split()))



    res = 1000000005

    if min(X) >= 0:

        print((X[K - 1]))

    elif max(X) <= 0:

        X = X[::-1]

        print((-X[K - 1]))

    else:

        res = min(res, solve(X, K))

        X = [-x for x in X]

        res = min(res, solve(X[::-1], K))

        print(res)

n,k = list(map(int,input().split()))

a = list(map(int,input().split()))

minus = []

plus = []

ans = 10**100

for x in a:

    if x <0:minus.append(-x)

    else:plus.append(x)

minus = minus[::-1]

for i in range(min(k+1,len(minus)+1)):#負のものをi個通る

    if k-i > len(plus):continue

    res = 0

    if i-1 >=0:res += minus[i-1]

    res*=2

    if k-i-1 >=0 and k-i <= len(plus):res += plus[k-i-1]

    ans = min(ans,res)

    res = 0

    if k-i-1 >=0 and  k-i <= len(plus):res += plus[k-i-1]

    res *=2

    if i-1 >=0:res += minus[i-1]

    ans = min(ans,res)

print(ans)



    

    

    

    
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


def solve(X, K):
    N = len(X)
    cumsum = [0 for _ in range(N)]
    for i in range(1, N):
        cumsum[i] = abs(X[i] - X[i - 1]) + cumsum[i - 1]
    idx_zero = bisect.bisect_left(X, 0)
    ret = 1000000005
    for i in range(0, N):
        if X[i] >= 0:
            break
        res = -X[i]
        k = idx_zero - i
        if (k < K) and (idx_zero + K - k - 1 < N):
            res += cumsum[idx_zero + K - k - 1] - cumsum[i]
            ret = min(ret, res)
    return ret


if __name__ == "__main__":
    N, K = list(map(int, input().split()))
    X = list(map(int, input().split()))
    res = 1000000005
    if min(X) >= 0:
        print((X[K - 1]))
    elif max(X) <= 0:
        X = X[::-1]
        print((-X[K - 1]))
    else:
        res = min(res, solve(X, K))
        X = [-x for x in X]
        res = min(res, solve(X[::-1], K))
        print(res)

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
minus = []
plus = []
ans = 10**100
for x in a:
    if x < 0:
        minus.append(-x)
    else:
        plus.append(x)
minus = minus[::-1]
for i in range(min(k + 1, len(minus) + 1)):  # 負のものをi個通る
    if k - i > len(plus):
        continue
    res = 0
    if i - 1 >= 0:
        res += minus[i - 1]
    res *= 2
    if k - i - 1 >= 0 and k - i <= len(plus):
        res += plus[k - i - 1]
    ans = min(ans, res)
    res = 0
    if k - i - 1 >= 0 and k - i <= len(plus):
        res += plus[k - i - 1]
    res *= 2
    if i - 1 >= 0:
        res += minus[i - 1]
    ans = min(ans, res)
print(ans)

-import sys -import math  # noqa -import bisect  # noqa -import queue  # noqa - - -def input(): -    return sys.stdin.readline().rstrip() - - -def solve(X, K): -    N = len(X) -    cumsum = [0 for _ in range(N)] -    for i in range(1, N): -        cumsum[i] = abs(X[i] - X[i - 1]) + cumsum[i - 1] -    idx_zero = bisect.bisect_left(X, 0) -    ret = 1000000005 -    for i in range(0, N): -        if X[i] >= 0: -            break -        res = -X[i] -        k = idx_zero - i -        if (k < K) and (idx_zero + K - k - 1 < N): -            res += cumsum[idx_zero + K - k - 1] - cumsum[i] -            ret = min(ret, res) -    return ret - - -if __name__ == "__main__": -    N, K = list(map(int, input().split())) -    X = list(map(int, input().split())) -    res = 1000000005 -    if min(X) >= 0: -        print((X[K - 1])) -    elif max(X) <= 0: -        X = X[::-1] -        print((-X[K - 1])) +n, k = list(map(int, input().split())) +a = list(map(int, input().split())) +minus = [] +plus = [] +ans = 10**100 +for x in a: +    if x < 0: +        minus.append(-x) -        res = min(res, solve(X, K)) -        X = [-x for x in X] -        res = min(res, solve(X[::-1], K)) -        print(res) +        plus.append(x) +minus = minus[::-1] +for i in range(min(k + 1, len(minus) + 1)):  # 負のものをi個通る +    if k - i > len(plus): +        continue +    res = 0 +    if i - 1 >= 0: +        res += minus[i - 1] +    res *= 2 +    if k - i - 1 >= 0 and k - i <= len(plus): +        res += plus[k - i - 1] +    ans = min(ans, res) +    res = 0 +    if k - i - 1 >= 0 and k - i <= len(plus): +        res += plus[k - i - 1] +    res *= 2 +    if i - 1 >= 0: +        res += minus[i - 1] +    ans = min(ans, res) +print(ans)