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