#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int L,N,X[100]; const int M = (int)1e5; int dp[2][2*M+1]; void solve() { cin >> L >> N; for(int i = 0;i < N;i++) cin >> X[i]; int cur = 0; dp[cur][M] = 1; for(int i = 1;i < N;i++) { int d = X[i]-X[i-1]; int nxt = 1-cur; for(int j = -M;j <= M;j++) dp[nxt][j+M] = 0; for(int j = -M;j <= M;j++) { { int nj = j + d; if(-M <= nj && nj <= M) dp[nxt][nj+M] |= dp[cur][j+M]; } { int nj = j - d; if(-M <= nj && nj <= M) dp[nxt][nj+M] |= dp[cur][j+M]; } } cur = nxt; } int ans = (int)2e9; for(int j = -M;j <= M;j++) if(dp[cur][j+M]) { int val = j + X[0] - (L-X[N-1]); ans = min(ans,abs(val)); } cout << ans << endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int tt = 1; /* cin >> tt; */ while(tt--) solve(); }