#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e3 + 10;
const long long Mod = 1e9 + 7;
long long dp[MAXN][MAXN];
long long a[MAXN];
long long e[MAXN];
long long rev[MAXN];
long long fact[MAXN];
long long pw(long long x, long long n) {
  if (n == 0) {
    return 1;
  }
  long long d = pw(x, n / 2);
  d *= d;
  d %= Mod;
  if (n & 1) {
    d *= x;
    d %= Mod;
  }
  return d;
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  fact[0] = 1;
  for (long long i = 1; i <= n; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= Mod;
    rev[i] = pw(fact[i], Mod - 2);
  }
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] != -1) {
      if (a[i] == i) {
        cout << 0;
        return 0;
      }
      e[i]++;
      e[a[i]]++;
    }
  }
  dp[0][1] = 0;
  dp[0][2] = 1;
  for (long long i = 3; i <= n; i++) {
    dp[0][i] = (i - 1) * (dp[0][i - 1] + dp[0][i - 2]);
    dp[0][i] %= Mod;
  }
  dp[0][0] = 1;
  for (long long i = 1; i <= n; i++) {
    long long u = dp[i - 1][0];
    dp[i][0] = dp[i - 1][0] * i;
    dp[i][0] %= Mod;
    for (long long j = 1; j <= n; j++) {
      u += (rev[j] * dp[i - 1][j]);
      u %= Mod;
      dp[i][j] = ((u * fact[j]) % Mod) * i;
      dp[i][j] %= Mod;
    }
  }
  long long k = 0, w = 0;
  for (long long i = 1; i <= n; i++) {
    k += (e[i] == 0);
    w += (e[i] == 1);
  }
  w /= 2;
  cout << dp[w][k];
}
