#include using namespace std; using ll = long long; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); int L, N, ans=1e9; cin >> L >> N; vector x(N+1); for (int i=1; i<=N; i++) cin >> x[i]; vector dp(vector(L+1, vector(2))); dp[0][0] = 1; for (int i=1; i<=N; i++){ vector pd(vector(L+1, vector(2))); for (int j=0; j<=L; j++){ if (j-(x[i]-x[i-1])>=0){ pd[j][0] = pd[j][0] | dp[j-(x[i]-x[i-1])][0]; pd[j][1] = pd[j][1] | dp[j-(x[i]-x[i-1])][0]; } pd[j][0] = pd[j][0] | dp[j][1]; pd[j][1] = pd[j][1] | dp[j][1]; } swap(dp, pd); } for (int i=0; i<=L; i++){ if (dp[i][0]) ans = min(ans, abs(i-(L-i))); } cout << ans << endl; return 0; }