#pragma GCC optimize("O2") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define int ll #define INT128_MAX (__int128)(((unsigned __int128) 1 << ((sizeof(__int128) * __CHAR_BIT__) - 1)) - 1) #define INT128_MIN (-INT128_MAX - 1) namespace R = std::ranges; namespace V = std::views; using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair; using pll = pair; using tiii = tuple; using ldb = long double; //#define double ldb template ostream& operator<<(ostream& os, const pair pr) { return os << pr.first << ' ' << pr.second; } template ostream& operator<<(ostream& os, const array &arr) { for(const T &X : arr) os << X << ' '; return os; } template ostream& operator<<(ostream& os, const vector &vec) { for(const T &X : vec) os << X << ' '; return os; } signed main() { ios::sync_with_stdio(false), cin.tie(NULL); int l, n; cin >> l >> n; vector x(n + 2); for(int i = 1; i <= n; i++) cin >> x[i]; x[n + 1] = l; vector dp(2 * l + 1, vector(2, false)); dp[x[1] + l][0] = true; for(int i = 2; i <= n + 1; i++) { vector tmp(2 * l + 1, vector(2, false)); for(int j = -l; j <= l; j++) for(int k : {0, 1}) if (dp[j + l][k]) tmp[j + l + x[i] - x[i - 1]][k] = tmp[x[i] - x[i - 1] - j + l][1 - k] = true; dp.swap(tmp); } int ans = INT_MAX; for(int j = -l; j <= l; j++) if (abs(j) < ans and dp[j + l][1]) ans = abs(j); cout << ans << '\n'; return 0; }