l, n = map(int, input().split()) X = list(map(int, input().split())) X = [0] + X + [l] D = [] for i in range(n + 1): D.append(X[i + 1] - X[i]) a = D[0] b = D[-1] D = D[1:-1] l = sum(D) DP = [[False for _ in range(l + 1)] for _ in range(n)] DP[0][0] = True for i in range(n - 1): for j in range(l + 1): DP[i + 1][j] |= DP[i][j] if j + D[i] <= l: DP[i + 1][j + D[i]] |= DP[i][j] ans = 10**18 for i in range(l + 1): if DP[n - 1][i]: ans = min(ans, abs(a + i - b - (l - i))) print(ans)