#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007LL;
vector<vector<long long> > B;
vector<vector<long long> > v;
vector<long long> F, D;
long long sol(long long s, long long w) {
  if (w == 0) return F[s];
  if (s == 0) return D[w];
  if (v[s][w] != -1) return v[s][w];
  long long res = 0;
  for (long long k = 0; k < min(s, w) + 1; k++) {
    long long ap = B[w][k] * B[s][s - k];
    ap %= MOD;
    ap *= F[s];
    ap %= MOD;
    ap *= sol(k, w - k);
    ap %= MOD;
    res += ap;
    res %= MOD;
  }
  return v[s][w] = res;
}
int main() {
  B = vector<vector<long long> >(2010, vector<long long>(2010));
  B[0][0] = 1;
  for (long long i = 1; i <= 2005; i++) {
    B[i][0] = 1;
    for (long long j = 1; j <= 2005; j++) {
      B[i][j] = B[i - 1][j - 1] + B[i - 1][j];
      B[i][j] %= MOD;
    }
  }
  F = vector<long long>(2010);
  F[0] = 1;
  for (long long i = 1; i <= 2005; i++) F[i] = (F[i - 1] * i) % MOD;
  D = vector<long long>(2010);
  D[0] = 1;
  for (long long i = 1; i <= 2005; i++) {
    long long sum = 0;
    for (long long k = 0; k < i + 1; k++) {
      if (k % 2)
        sum -= ((F[k] * B[i][k]) % MOD);
      else
        sum += ((F[k] * B[i][k]) % MOD);
      sum %= MOD;
    }
    if (i % 2)
      D[i] = -sum;
    else
      D[i] = sum;
  }
  long long n, a;
  cin >> n;
  v = vector<vector<long long> >(2005, vector<long long>(2005, -1));
  long long s = 0, w = 0;
  vector<long long> inp(n + 5);
  vector<bool> tou(n + 5);
  for (long long i = 0; i < n; i++) {
    cin >> inp[i];
    inp[i]--;
    if (inp[i] >= 0) tou[inp[i]] = true;
  }
  for (long long i = 0; i < n; i++) {
    if (inp[i] == -2) {
      if (tou[i])
        ++s;
      else
        ++w;
    }
  }
  cout << sol(s, w) << endl;
}
