#include using namespace std; int ans[1300][1300]; int a[1300],i,j,k,n,res; int fc[1300][1300]; int fq[1300],_fq[1300]; int mypow(int A,int B) { if (!B) return 1; long long D=mypow(A,B/2); D=(D*D)%1000000007; if (B%2) D*=A; return D%1000000007; } int main() { cin>>n; for (i=1;i<=n;i++) cin>>a[i]; fq[0]=_fq[0]=1; for (i=1;i<=n;i++) fq[i]=(1LL*fq[i-1]*i)%1000000007, _fq[i]=mypow(fq[i],1000000005); for (i=1;i<=n;i++) for (j=0;j<=i;j++) fc[i][j]=(1LL*fq[i]*_fq[i-j])%1000000007; ans[n+1][0]=1; for (i=n+1;i>=1;i--) for (j=i-1;j>=1;j--) { if (j a[j+1]) break; for (k=0;k<=i-j;k++) ans[j][i-j]=(ans[j][i-j]+1LL*ans[i][k]*fc[i-j][k])%1000000007; } res=0; for (i=0;i<=n;i++) res=(res+ans[1][i])%1000000007; cout<