import sys input = sys.stdin.readline L, N = map(int, input().split()) X = list(map(int, input().split())) A = [] bk = 0 for i in range(N): A.append(X[i]-bk) bk = X[i] A.append(L-bk) dp = set() dp.add(0) for i in range(1, len(A)-1): ndp = set() for d in dp: ndp.add(d) ndp.add(d+A[i]) dp = ndp a = A[0] b = A[-1] ans = L for d in dp: ans = min(ans, abs((a+d) - (b+L-(a+b)-d))) print(ans)