#include <bits/stdc++.h>
using namespace std;
int a[1000000], sum[1000000];
int main() {
  int i, j, n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    sum[i] = sum[i - 1] + a[i];
  }
  int ans = 0;
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++)
      ans = max(sum[n] + j - i + 1 - 2 * (sum[j] - sum[i - 1]), ans);
  cout << ans << endl;
  return 0;
}
