#include<bits/stdc++.h>
using namespace std;
int n, a[200100], ans = 0;
int fmx() {
int maxn = 0, sum = 0;
for(int i = 1; i <= n; i ++) {
maxn = max(a[i], maxn + a[i]);
sum = max(sum, maxn);
}
return sum;
}
int fmn() {
int minn = 0, sum = 0;
for(int i = 1; i <= n; i ++) {
minn = min(a[i], minn + a[i]);
sum = min(sum, minn);
}
return sum;
}
int main() {
freopen("count1s.in", "r", stdin);
freopen("count1s.out", "w", stdout);
cin >> n;
for(int i = 1; i <= n; i ++) {
cin >> a[i];
if(a[i] == 0) {
a[i] = -1;
}
}
cout << fmx() - fmn() + 1 << endl;
return 0;
}