#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k = -2, n, x = 0, u = 1, v = 0;
  cin >> n;
  for (i = 1; i < n; i++) {
    cin >> x;
    if (x != 0) break;
  }
  if (x == 0) {
    cout << n << endl;
    return 0;
  }
  for (j = i + 1; j < n; j++) {
    cin >> x;
    if (x)
      u++;
    else
      v++;
    if (v - u > k) k = v - u;
  }
  cin >> x;
  if (x)
    u++;
  else
    v++;
  if (v - u > k) k = v - u;
  cout << max(k, 0) + u + i - 1 << endl;
}
