#include <bits/stdc++.h>
int max(int a, int b, int c) {
  if (a < b) a = b;
  if (a < c) a = c;
  return a;
}
int main(void) {
  int i, n;
  char input[100];
  int do_nothing[100];
  int last_fliped[100];
  int last_not_fliped[100];
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%hhd", &input[i]);
  }
  do_nothing[0] = last_not_fliped[0] = input[0];
  last_fliped[0] = 1 - input[0];
  for (i = 1; i < n; i++) {
    do_nothing[i] = do_nothing[i - 1] + input[i];
    last_fliped[i] =
        max(do_nothing[i - 1], last_fliped[i - 1], 0) + 1 - input[i];
    last_not_fliped[i] =
        max(do_nothing[i - 1], last_fliped[i - 1], last_not_fliped[i - 1]) +
        input[i];
  }
  if (do_nothing[n - 1] == last_not_fliped[n - 1]) {
    printf("%d", last_fliped[n - 1]);
  } else {
    printf("%d", max(last_fliped[n - 1], last_not_fliped[n - 1], 0));
  }
  return 0;
}
