import sys input = sys.stdin.buffer.readline L, N = map(int, input().split()) X = list(map(int, input().split())) X.append(L) for i in range(N, 0, -1): X[i] -= X[i - 1] dp0 = 1 << L dp1 = 0 for x in X: dp0 <<= x dp1 >>= x if N: N -= 1 dp0 = dp1 = dp0 | dp1 ans = bin(dp1)[:1:-1] print(min(abs(i - L) for i, c in enumerate(ans) if c == '1'))