N, M = map(int, input().split()) D = [int(input()) for _ in range(M)] ans = float('inf') for i in range(M - N + 1): ans = min(ans, min(abs(D[i]), abs(D[i + N - 1])) + abs(D[i + N - 1] - D[i])) print(ans)