#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
namespace inp {
template <class A>
void read(vector<A> &v);
template <class A, size_t S>
void read(array<A, S> &a);
template <class T>
void read(T &x) {
  cin >> x;
}
void read(double &d) {
  string t;
  read(t);
  d = stod(t);
}
void read(long double &d) {
  string t;
  read(t);
  d = stold(t);
}
template <class H, class... T>
void read(H &h, T &...t) {
  read(h);
  read(t...);
}
template <class A>
void read(vector<A> &x) {
  for (auto &a : x) read(a);
}
template <class A, size_t S>
void read(array<A, S> &x) {
  for (auto &a : x) read(a);
}
}  // namespace inp
using namespace inp;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int64_t randint(int64_t a, int64_t b) {
  return uniform_int_distribution<int64_t>(a, b)(rng);
}
void solve() {
  int n;
  read(n);
  string a;
  string s = "";
  for (int i = (0); i < (n); ++i) {
    char c;
    read(c);
    a += c;
  }
  s = a + a;
  vector<char> vc;
  for (auto &x : s) {
    vc.push_back(x);
  }
  int con = 1;
  int tem = 1;
  for (int i = (1); i < (s.size()); ++i) {
    if (s[i] == '1' && s[i - 1] == '1') {
      tem++;
    } else {
      con = max(tem, con);
      tem = 1;
    }
  }
  if (count(vc.begin(), vc.end(), '0') == 2 * n) {
    cout << 0 << "\n";
    return;
  }
  cout << con << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
