#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 2005;
const int MOD = 1e9 + 7;
ll dp[maxn], f[maxn];
int a[maxn], pos[maxn], vis[maxn];
int main() {
  int n;
  while (~scanf("%d", &n)) {
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      vis[a[i]] = 1;
      if (a[i] == -1) continue;
      pos[i] = 1;
    }
    f[0] = 1;
    for (int i = 1; i <= n; i++) {
      f[i] = f[i - 1] * i % MOD;
    }
    int cnt1 = 0, cnt2 = 0;
    for (int i = 1; i <= n; i++) {
      if (!vis[i]) {
        if (!pos[i])
          ++cnt1;
        else
          ++cnt2;
      }
    }
    dp[0] = 1;
    for (int i = 1; i <= cnt1; i++) {
      dp[i] = (dp[i] + dp[i - 1] * cnt2 % MOD) % MOD;
      ll t = ((i - 1) % MOD + MOD) % MOD;
      dp[i] = (dp[i] + dp[i - 1] * t % MOD) % MOD;
      if (i >= 2) dp[i] = (dp[i] + dp[i - 2] * t % MOD);
    }
    printf("%lld\n", dp[cnt1] * f[cnt2] % MOD);
  }
}
