#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 7, M = 2e6;
const long long mod = 1e9 + 7;
inline int read() {
  int ret = 0;
  char ch = getchar();
  bool f = 1;
  for (; !isdigit(ch); ch = getchar()) f ^= !(ch ^ '-');
  for (; isdigit(ch); ch = getchar()) ret = (ret << 1) + (ret << 3) + ch - 48;
  return f ? ret : -ret;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long ksm(long long a, long long b, long long mod) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}
long long inv2(long long a, long long mod) { return ksm(a, mod - 2, mod); }
int a[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    a[i + n] = a[i];
  }
  a[0] = 0;
  int fi = 0;
  int ans = 0, res = 0;
  for (int i = 1; i <= 2 * n; i++) {
    if (a[i] == 0) {
      ans = 0;
    } else {
      if (ans == 0) {
        fi = i;
      }
      if (i - fi + 1 > n) ans--;
      ans++;
      res = max(ans, res);
    }
  }
  printf("%d\n", res);
  return 0;
}
