#include<cstdio> using namespace std; typedef long long ll; const int N=2005; const ll mod=1e9+7; int n,X,Y,a[N];bool flag[N]; ll f[N]; int main(){ scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",&a[i]); if(~a[i]) flag[a[i]]=1; } for(int i=1;i<=n;i++){ if(!(~a[i])){ if(flag[i]) X++; else Y++; } } f[0]=1; for(int i=1;i<=X;i++) f[0]=f[0]*i%mod; for(int i=1;i<=Y;i++){ f[i]=(X+i-1)*f[i-1]%mod; if(i>1){ f[i]=(f[i]+(i-1)*f[i-2])%mod; } } printf("%I64d",f[Y]); return 0; }