#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e3;
int n, a[MAX], ps[MAX], ans;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) ps[i] = ps[i - 1] + a[i];
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++) {
      int cnt1 = ps[j] - ps[i - 1], cnt0 = j - i + 1 - cnt1;
      ans = max(ps[n] - cnt1 + cnt0, ans);
    }
  cout << ans;
  return 0;
}
