#include //#include using namespace std; //using namespace atcoder; //using mint = modint998244353; #define rep(i,n) for(long long i=0;i vec; typedef vector> vvec; typedef vector vecll; typedef vector> vvecll; //#include //using namespace boost::multiprecision; const ll mod=998244353; //const ll mod=1e9+7; const ll INF=5e18; const int INT_INF=1e9; const double pi=3.14159265358979; //xのn乗をpで割ったあまりを求める ll modpow(ll x,ll n,ll p=mod){ if(n==0) return 1; if(n%2==1) return (x*modpow(x,n-1,p))%p; else{ ll t=modpow(x,n/2,p); assert(t>0); return (t*t)%p; } } //xの逆元(p:素数) ll inv(ll x,ll p=mod){ return modpow(x,p-2,p); } template int index(vector &a, T x){ return lower_bound(all(a),x)-a.begin(); } int idx(int n){ return n+100000; } int main(){ int l,n; cin >> l >> n; vec x(n+1,l); rep(i,n) cin >> x[i]; vector dp(200001,false); dp[idx(x[0])]=true; rep1(i,n-1){ vector ndp(200001,false); rep(j,200001){ if(dp[j]){ ndp[j+x[i]-x[i-1]]=true; ndp[j+x[i-1]-x[i]]=true; } } dp=move(ndp); } vector ndp(200001,false); rep(j,200001){ if(dp[j]){ ndp[j+x[n-1]-x[n]]=true; } } dp=move(ndp); int ans; rep(i,100001){ if(dp[idx(i)]||dp[idx(-i)]){ ans=i; break; } } cout << ans << endl; }