#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  if (count(a, a + n, 1) == n) {
    cout << n - 1;
    return 0;
  }
  int max = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i; j <= n; j++) {
      int temp =
          count(a, a + i, 1) + count(a + i, a + j, 0) + count(a + j, a + n, 1);
      if (temp > max) {
        max = temp;
      }
    }
  }
  cout << max << endl;
  return 0;
}
