# Original solution
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    global N, K, results
    results = []
    N, K = LI()
    X = LI()
    # すべて正にする
    if N == 1 and K == 1 and X == [0]:
        print(0)
        return
    min_x = min(X)
    if min_x < 0:
        X = [x - min_x for x in X]
        # 貪欲的にいく？
        dfs(-min_x, 0, X, 0, 0)
    else:
        dfs(0, 0, X, 0, 0)

    print(min(results))


def dfs(p, s, rest, pidx, count):
    global N, K, results
    # 該当のものを使うか
    # 右に行くか左に行くかの判断
    # k個選んだら終了
    if count == K:
        results.append(s)
        return

    if rest[-1] < p:
        # 右側には数字がない
        dfs(rest[-1], s+p-rest[-1], rest[:-1], 0, count+1)
        return

    if rest[0] > p:
        # 左側に数字がない
        # K個選んで終わり
        dfs(rest[0], s+rest[0] - p, rest[1:], 0, count+1)
        return

    if pidx == 0:
        for ridx, r in enumerate(rest):
            if r > p:
                left = rest[ridx - 1]
                new_rest = rest[:ridx-1] + rest[ridx:]
                dfs(left, s + p - left, new_rest, ridx - 1, count+1)

                right = r
                new_rest = rest[:ridx] + rest[ridx+1:]
                dfs(right, s + right - p, new_rest, ridx, count+1)
                return
    else:
        left = rest[pidx - 1]
        new_rest = rest[:pidx-1] + rest[pidx:]
        dfs(left, s+p-left, new_rest, pidx - 1, count+1)

        right = rest[pidx]
        new_rest = rest[:pidx] + rest[pidx+1:]
        dfs(right, s+right - p, new_rest, pidx, count+1)



if __name__ == "__main__":
    main()
	


# Optimized solution
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    global N, K, results
    global right_items, left_items, start_point
    results = []
    N, K = LI()
    X = LI()

    if K == 1 and X == [0]:
        print(0)
        return

    if 0 in X:
        X.remove(0)
        K -= 1
        N -= 1

    if min(X) > 0:
        # 右側しか見ない
        print(max(X[:K]))
        return

    if max(X) < 0:
        # 左側しかみない
        print(abs(min(X[-K:])))
        return

    left_part = []
    right_part = []
    for i in X:
        if i < 0:
            left_part.append(abs(i))
        else:
            right_part.append(i)

    left_part = left_part[::-1][:K]
    right_part = right_part[:K]

    result = 10**8
    for i in range(0, K):
        #  left = d(left_part[:i], 0, 0)
        if len(left_part[:i]) + len(right_part[:K-i]) != K:
            continue
        if len(left_part[:i]) == 0:
            left_distance = 0
        else:
            left_distance = left_part[:i][-1]
        #  right = d(right_part[:K-i], 0, 0)
        if len(right_part[:K-i]) == 0:
            right_distance = 0
        else:
            right_distance = right_part[:K-i][-1]
        #  print('i, left, right', i, left, right)
        #  print('i, left, right', i, left_distance, right_distance)
        #  first = min(left, right)
        #  second = max(left, right)
        first = min(left_distance, right_distance)
        second = max(left_distance, right_distance)
        #  result = min(result, first*2+second)
        result = min(result, first*2+second)

    print(result)


#  def d(arr, s, current_idx):
#      if len(arr) == 0:
#          return 0
#      if len(arr) == 1:
#          return arr[0]

#      print(arr, s)

#      if current_idx == 0:
#          s += arr[0]
#          return d(arr, s, current_idx + 1)

#      if current_idx == len(arr) - 1:
#          return s + arr[current_idx] - arr[current_idx - 1]

#      s += arr[current_idx] - arr[current_idx - 1]
#      return d(arr, s, current_idx + 1)

if __name__ == "__main__":
    main()