#include <bits/stdc++.h>
using namespace std;
int pre[2005], nxt[2005];
int main() {
  int n;
  int hig[2005], me[2005];
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &hig[i]);
  for (int i = 1; i <= n; ++i) {
    me[i] = 1;
    for (int j = 1; j < i; ++j)
      if (hig[i] >= hig[j] && me[j] + 1 > me[i]) {
        me[i] = me[j] + 1;
      }
    pre[i] = max(me[i], pre[i - 1]);
  }
  for (int i = n; i >= 1; --i) {
    me[i] = 1;
    for (int j = n; j > i; --j)
      if (hig[j] >= hig[i] && me[j] + 1 > me[i]) me[i] = me[j] + 1;
    nxt[i] = max(me[i], nxt[i + 1]);
  }
  int mmax = 0;
  for (int i = 1; i <= n; ++i) mmax = max(mmax, pre[i] + nxt[i + 1]);
  printf("%d\n", mmax);
  return 0;
}
