#include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } const int X = 100000; bool ok[105][2][200005]; void set_ok(int i, int j, int k, bool f){ ok[i][j][k+X] = f; } bool get_ok(int i, int j, int k){ return ok[i][j][k+X]; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int l, n; cin >> l >> n; vector x(n+2); for(int i = 1; i <= n; i++) cin >> x[i]; x[n+1] = l; set_ok(0, 0, 0, true); for(int i = 1; i <= n+1; i++){ int len = x[i]-x[i-1]; for(int j = 0; j < 2; j++){ for(int diff = -l; diff <= l; diff++){ if(!get_ok(i-1, j, diff)) continue; int diff_next = [&](){ if(j == 0) return diff+len; return diff-len; }(); if(i != 1){ set_ok(i, j, diff_next, true); } diff_next = [&](){ if(j == 0) return diff-len; return diff+len; }(); set_ok(i, j^1, diff_next, true); } } } int ans = l; for(int diff = -l; diff <= l; diff++){ if(get_ok(n+1, 0, diff)) { chmin(ans, abs(diff)); } } cout << ans << endl; }