#include using namespace std; //* ATCODER #include using namespace atcoder; typedef modint998244353 mint; //*/ /* BOOST MULTIPRECISION #include using namespace boost::multiprecision; //*/ typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) template bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template T max(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]); return ret; } template T min(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]); return ret; } template T sum(vector &a){ T ret = 0; for (int i=0; i<(int)a.size(); i++) ret += a[i]; return ret; } // importbisect template int bisect_left(vector &X, T v){ return lower_bound(X.begin(), X.end(), v) - X.begin(); } template int bisect_right(vector &X, T v){ return upper_bound(X.begin(), X.end(), v) - X.begin(); } // ----- typedef bitset<3141592> B; int main(){ int l, n; cin >> l >> n; vector x(n+1); int nw = 0; rep(i,0,n){ int y; cin >> y; x[i] = y - nw; nw = y; } x[n] = l - nw; n++; int base = 1500000; B dp0; B dp1; dp0[base + x[0]] = 1; rep(i,1,n){ B ndp0; B ndp1; ndp0 |= dp0 << x[i]; ndp0 |= dp1 << x[i]; ndp1 |= dp0 >> x[i]; ndp1 |= dp1 >> x[i]; dp0 = ndp0; dp1 = ndp1; } int ans = 1e9; rep(i,0,3141592){ if (!dp1[i]) continue; chmin(ans, abs(base - i)); } cout << ans << '\n'; }