#include using namespace std; #include using namespace atcoder; #define rep(i, n) for(int i=0;i<(n);++i) #define rep1(i, n) for(int i=1;i<=(n);i++) #define ll long long using mint = modint998244353; using P = pair; using lb = long double; using T = tuple; #ifdef LOCAL # include # define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__) #else # define dbg(...) (static_cast(0)) #endif int main() { int l, n; cin >> l >> n; vector x(n+2); rep(i,n) cin >> x[i+1]; x[n+1] = l; vector>> dp(n+2, vector>(2)); dp[0][0][l] = 1; rep(i,n+1){ for(int j=i+1;j<=n+1;j++){ dp[j][1] |= dp[i][0]<<(x[j]-x[i]); dp[j][0] |= dp[i][1]>>(x[j]-x[i]); } } int ans = 1e9; for(int j=0;j<=2*l;j++){ if(dp[n+1][0][j]) ans = min(ans, abs(l-j)); } cout << ans << endl; return 0; }