#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, b = 0, c = 0, f, t = 0, u = 0, v = 0;
  cin >> n;
  f = n - 1;
  int a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  if (a[0] == 0 || a[n - 1] == 0) {
    for (i = 0; i < n; i++) {
      if (a[i] == 1) {
        b++;
      }
      if (a[i] == 0 || i == f) {
        if (b > c) {
          c = b;
        }
        b = 0;
      }
    }
    cout << c << endl;
  } else {
    for (i = 0; i < n; i++) {
      if (a[i] == 1) {
        b++;
      }
      v = b;
      if (a[i] == 0 || i == f) {
        t++;
        if (b > c) {
          c = b;
        }
        if (t == 1) {
          u = b;
        }
        b = 0;
      }
    }
    if (v + u > c)
      cout << v + u << endl;
    else
      cout << c << endl;
  }
}
