#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, c0 = 0, c11 = 0;
  cin >> n;
  long long arr[n];
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] == 0) c0++;
    if (arr[i] == 1) c11++;
  }
  long long maxcount = INT_MIN;
  long long count = 0;
  for (long long i = 0; i < n; i++) {
    if (arr[i] == 1)
      count++;
    else {
      maxcount = max(maxcount, count);
      count = 0;
    }
    if (arr[n - 1] == 1) maxcount = max(maxcount, count);
  }
  long long c1 = 0;
  if (c0 == n) {
    cout << "0";
    exit(0);
  }
  if (c11 == n) {
    cout << n;
    exit(0);
  }
  if (c0 > 0) {
    if (arr[0] == 1 && arr[n - 1] == 1) {
      for (long long i = 1; i < n - 1; i++) {
        if (arr[i] == 0) break;
        c1++;
      }
      for (long long j = n - 2; j >= 0; j--) {
        if (arr[j] == 0) break;
        c1++;
      }
      maxcount = max(maxcount, c1 + 2);
    }
  }
  cout << maxcount << endl;
}
