#include <bits/stdc++.h>
const int N = 2e5+10;
int n;
int a[N];
int findMax() {
int ans = 0, res = 0;
for (int i = 1; i <= n; ++ i)
ans = std::max(a[i], ans + a[i]), res = std::max(res, ans);
return res;
}
int findMin() {
int ans = 0, res = 0;
for (int i = 1; i <= n; ++ i)
ans = std::min(a[i], ans + a[i]), res = std::min(res, ans);
return res;
}
int main() {
freopen("count1s.in", "r", stdin);
freopen("count1s.out", "w", stdout);
std::cin >> n;
for (int i = 1; i <= n; ++ i) std::cin >> a[i];
for (int i = 1; i <= n; ++ i) a[i] = a[i] ? -1 : 1;
std::cout << findMax() - findMin() + 1;
return 0;
}