#include using namespace std; int main() { int L, N; cin >> L >> N; vector X(N + 2); X[0] = 0; X[N + 1] = L; for (int i = 0; i < N; i++) { int x; cin >> x; X[i + 1] = x; } vector A; for (int i = 0; i < N + 1; i++) { A.push_back(X[i + 1] - X[i]); } N = A.size(); int M = 2 * L + 10; vector>> dp(N + 1, vector>(M, vector(2))); dp[0][L][0] = 1; for (int i = 0; i < N; i++) { int a = A[i]; for (int j = 0; j < M; j++) { for (int k = 0; k < 2; k++) { if (dp[i][j][k] == 0) { continue; } if (k == 0) { dp[i + 1][j + a][k] = 1; if (i > 0) { dp[i + 1][j - a][1 - k] = 1; } } else { dp[i + 1][j - a][k] = 1; if (i > 0) { dp[i + 1][j + a][1 - k] = 1; } } } } } int ans = pow(10, 9); for (int j = 0; j < M; j++) { if (dp[N][j][1] == 1) { ans = min(ans, abs(j - L)); } } cout << ans << endl; }