#include <bits/stdc++.h>
using namespace std;
int n, ans;
int a[2020], nxt[2020], pre[2020], d[2020];
int getnum() {
  char c = getchar();
  int num = 0;
  while (c > '9' || c < '0') c = getchar();
  while (c >= '0' && c <= '9')
    num = (num << 3) + (num << 1) + c - '0', c = getchar();
  return num;
}
int main() {
  int i, j, tm;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= n; i++) {
    pre[i] = 1;
    for (j = 1; j < i; j++)
      if (a[j] <= a[i]) pre[i] = max(pre[i], pre[j] + 1);
  }
  for (i = n; i >= 1; i--) {
    nxt[i] = 1;
    for (j = n; j > i; j--)
      if (a[j] >= a[i]) nxt[i] = max(nxt[i], nxt[j] + 1);
  }
  for (i = 1; i <= n; i++) ans = max(ans, pre[i - 1] + nxt[i]);
  printf("%d\n", ans);
}
