#include <bits/stdc++.h>
using namespace std;
struct point {
  int x, y, ind;
  char ch;
};
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long Com[1005][1005];
void comfunc() {
  for (long long i = 0; i <= 1000; i++) {
    Com[i][0] = 1;
    for (long long j = 1; j <= i; j++) {
      Com[i][j] = (Com[i - 1][j - 1] + Com[i - 1][j]) % mod;
    }
  }
}
long long fact[13];
void factorial() {
  fact[0] = 1;
  for (long long i = 1; i < 12; i++) fact[i] = (fact[i - 1] * i);
}
bool cmp(point A, point B) {
  if (A.x != B.x) return A.x < B.x;
  return A.y < B.y;
}
long long n, m, ans, ok, flag, a[105], cnt0, cnt1, t;
int main() {
  t = 1;
  while (t--) {
    cin >> n;
    cnt0 = 0, cnt1 = 0;
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
      if (a[i] == 0) {
        cnt0++;
      }
    }
    cnt1 = n - cnt0;
    long long one = 0, zero = 0, cnt2 = 0, cnt = 0, mx = 0, maxcnt0 = 0,
              maxone = 0, maxzero = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] == 0) {
        mx++;
        maxcnt0 = max(maxcnt0, mx);
      } else {
        mx = 0;
      }
    }
    for (int j = 0; j < n; j++) {
      cnt = 0;
      one = 0;
      for (int i = j; i < n; i++) {
        if (a[i] == 0) {
          cnt++;
        } else {
          maxone = max(maxone, cnt + cnt1 - one);
          one++;
        }
      }
    }
    for (int j = n - 1; j >= 0; j--) {
      cnt2 = 0, zero = 0;
      for (int i = j; i >= 0; i--) {
        if (a[i] == 0) {
          cnt2++;
        } else {
          maxzero = max(maxzero, cnt2 + cnt1 - zero);
          zero++;
        }
      }
    }
    ans = max(cnt0, max(maxcnt0 + cnt1, max(maxone, maxzero)));
    if (cnt1 == n) ans = n - 1;
    cout << ans << "\n";
  }
  return 0;
}
