#include <bits/stdc++.h>
using namespace std;
long long fact[2001];
long long C[2001][2001];
void init(int n) {
  C[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    C[i][0] = 1;
    C[i][i] = 1;
    for (int j = 1; j < i; ++j) {
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % 1000000007;
    }
  }
  fact[0] = 1;
  for (int i = 1; i <= n; ++i) {
    fact[i] = ((long long)(fact[i - 1]) * i) % 1000000007;
  }
}
int main(int argc, char *argv[]) {
  int P[2001];
  int n;
  cin >> n;
  int neg = 0;
  int a = 0, b = 0;
  set<int> fixed;
  for (int i = 0; i < n; ++i) {
    cin >> P[i];
    if (P[i] == -1) {
      ++neg;
    } else {
      fixed.insert(P[i]);
    }
  }
  init(neg);
  for (int i = 0; i < n; ++i)
    if (P[i] == -1) {
      if (fixed.find(i + 1) != fixed.end()) {
        ++a;
      } else {
        ++b;
      }
    }
  long long total = fact[neg];
  for (int i = 1; i <= b; ++i) {
    long long sub = (fact[neg - i] * C[b][i]) % 1000000007;
    if (i % 2) {
      total = (total + (1000000007 - sub)) % 1000000007;
    } else {
      total = (total + sub) % 1000000007;
    }
  }
  cout << total << endl;
}
