#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void ZZ(const char* name, Arg1&& arg1) {
  std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  std::cerr.write(names, comma - names) << " = " << arg1;
  ZZ(comma, args...);
}
int main() {
  long long n, f = 0;
  cin >> n;
  string s = "";
  for (long long i = 0; i < n; i++) {
    long long b;
    cin >> b;
    if (b == 1) f = 1;
    if (b == 1)
      s += '1';
    else
      s += '0';
  }
  s += s;
  n = s.size();
  long long t1 = 1, ans = LLONG_MIN;
  for (int i = 0; i + 1 < n; ++i) {
    if (s[i] == s[i + 1] and s[i] == '1')
      t1++;
    else {
      ans = max(t1, ans);
      t1 = 1;
    }
  }
  ans = max(t1, ans);
  ans = min(n / 2, ans);
  if (f == 0)
    cout << 0;
  else
    cout << ans << endl;
  return 0;
}
