L, N = map(int, input().split()) X = list(map(int, input().split())) dp = [False]*L*2 dp[X[0]] = True for i in range(N-1): l = X[i+1] - X[i] ndp = [False]*L*2 for d in range(1-L, L): if dp[d]: ndp[d-l] = ndp[d+l] = True dp = ndp l = L - X[-1] m = min(abs(d-l) for d in range(1-L, L) if dp[d]) print(m)