#include <bits/stdc++.h>
using namespace std;
long long n, a[200015], dem = 0, ans = 0, b[200015];
int main() {
  int j = 1;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  a[0] = a[n];
  a[n + 1] = a[1];
  a[n + 2] = 0;
  for (int i = 0; i <= n + 2; i++) {
    if (a[i] == 1) {
      dem++;
      ans = max(ans, dem);
    }
    if (a[i] == 0) {
      b[j] = dem;
      j++;
      dem = 0;
    }
  }
  if (a[1] == 1 && a[n] == 1) {
    ans = max(ans, b[1] + b[j - 1] - 2);
    cout << ans;
  } else {
    if (ans == n + 2)
      cout << n;
    else
      cout << ans;
  }
}
