#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::vector;
int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
  }
  const long long mod = (long long)1e9 + 7LL;
  vector<vector<long long> > rooted(n, vector<long long>(n));
  vector<vector<long long> > non_rooted(n, vector<long long>(n));
  for (int i = 0; i < n; ++i) {
    rooted[i][i] = non_rooted[i][i] = 1;
  }
  for (int i = 0; i + 1 < n; ++i) {
    rooted[i][i + 1] = 1;
    non_rooted[i][i + 1] = (p[i] < p[i + 1] ? 2 : 1);
  }
  for (int sz = 3; sz <= n; ++sz) {
    for (int left = 0; left + sz <= n; ++left) {
      int right = left + sz - 1;
      rooted[left][right] = rooted[left + 1][right];
      for (int mid = left + 2; mid <= right; ++mid) {
        if (p[left + 1] > p[mid]) {
          continue;
        }
        rooted[left][right] +=
            (rooted[left + 1][mid - 1] * non_rooted[mid][right]) % mod;
      }
      rooted[left][right] %= mod;
      non_rooted[left][right] = rooted[left][right];
      for (int mid = left + 1; mid <= right; ++mid) {
        if (p[left] > p[mid]) {
          continue;
        }
        non_rooted[left][right] +=
            (rooted[left][mid - 1] * non_rooted[mid][right]) % mod;
      }
      non_rooted[left][right] %= mod;
    }
  }
  cout << rooted[0][n - 1];
  return 0;
}
