L, N = map(int, input().split()) X = [0] + list(map(int, input().split())) + [L] A = [] for i in range(N + 1): A.append(X[i + 1] - X[i]) N = len(A) M = 2 * L + 10 dp = [[[0] * 2 for _ in range(M)] for _ in range(N + 1)] dp[0][L][0] = 1 for i, a in enumerate(A): for j in range(M): for k in range(2): if not dp[i][j][k]: continue if not k: dp[i + 1][j + a][k] = 1 if i: dp[i + 1][j - a][1 - k] = 1 else: dp[i + 1][j - a][k] = 1 if i: dp[i + 1][j + a][1 - k] = 1 ans = 10 ** 18 for j in range(M): if dp[N][j][1]: ans = min(ans, abs(j - L)) print(ans) # for i in range(N + 1): # print(dp[i])