L, N = map(int, input().split()) X = list(map(int, input().split())) A = [X[0]] for i in range(N-1): A.append(X[i+1]-X[i]) sumA = sum(A) dp = [[False]*(sumA+1) for _ in range(len(A)+1)] dp[0][0] = True for i in range(len(A)): for j in range(sumA+1): if not dp[i][j]: continue if 1 <= i: dp[i+1][j] = True dp[i+1][j+A[i]] = True ans = 10**18 for i in range(sumA+1): if dp[-1][i]: ans = min(ans, abs(i-(L-i))) print(ans)