#include <bits/stdc++.h>
const int N = 600;
const int p = 1000000007;
int f[N][N], g[N], h[N][N];
int i, j, k, n;
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &g[i]);
  for (i = n; i > 0; i--) {
    memset(f, 0, sizeof(f));
    for (j = i; j <= n; j++) {
      if (i == j) f[j][0] = 1;
      for (k = i + 1; k <= j; k++)
        f[j][g[k]] = (f[j][g[k]] + 1LL * h[k][j] * f[k - 1][g[k] - 1]) % p;
      for (k = 1; k <= n; k++) f[j][k] = (f[j][k - 1] + f[j][k]) % p;
      h[i][j] = f[j][n];
    }
  }
  printf("%d", h[1][n]);
  return 0;
}
