#include <bits/stdc++.h>
const int MX = 2e5 + 69;
using namespace std;
const long long mod = 1e9 + 7;
const double eps = -1e9;
int n;
int a[MX];
int c[2222][2222][3];
pair<int, int> mx[2222];
int dp[2222][2222][3];
int solve(int x, int la, int s) {
  if (x > n) {
    return 0;
  }
  int &ans = dp[x][la][s];
  if (ans != -1) {
    return ans;
  }
  ans = 0;
  ans = max(ans, solve(x + 1, la, s));
  if (!s) {
    ans = max(ans, (a[x] >= a[la]) + solve(x + 1, (a[x] >= a[la] ? x : la), s));
    ans = max(ans,
              (a[x] <= a[la]) + solve(x + 1, (a[x] <= a[la] ? x : la), s + 1));
  } else if (s == 1) {
    ans = max(ans, (a[x] <= a[la]) + solve(x + 1, (a[x] <= a[la] ? x : la), s));
    ans = max(ans,
              (a[x] >= a[la]) + solve(x + 1, (a[x] >= a[la] ? x : la), s + 1));
  } else {
    ans = max(ans, (a[x] >= a[la]) + solve(x + 1, (a[x] >= a[la] ? x : la), s));
  }
  return ans;
}
int main() {
  memset(dp, -1, sizeof dp);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  cout << solve(1, 0, 0);
  return 0;
}
