# coding: utf-8 # Your code here! gomi, num = map(int, input().split()) plus = [1000000] minus = [-1000000] for i in range(num): a = int(input()) if a >= 0: plus.append(a) else: minus.append(a) plus.sort() minus.sort() minus.reverse() current = 0 count = 0 ans = 0 while(1): if abs(current - plus[0]) <= abs(current - minus[0]): ans += abs(current - plus[0]) current = plus.pop(0) count += 1 else: ans += abs(current - minus[0]) current = minus.pop(0) count += 1 if count >= gomi: break print(ans)