#include <bits/stdc++.h>
using namespace std;
vector<int> open;
bool broken[2001];
int a[2001];
long long fact[2001];
long long comb[2001][2001];
long long sol[2001];
int main() {
  int nn;
  cin >> nn;
  fact[0] = 1;
  for (int i = 1; i <= nn; ++i) {
    fact[i] = fact[i - 1] * i % 1000000007;
  }
  comb[0][0] = 1;
  for (int i = 1; i <= nn; ++i) {
    for (int j = 0; j <= i; ++j) {
      comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % 1000000007;
    }
  }
  for (int i = 1; i <= nn; ++i) {
    broken[i] = true;
  }
  for (int i = 1; i <= nn; ++i) {
    scanf("%d", &a[i]);
    if (a[i] == -1) {
      open.push_back(i);
    } else {
      broken[a[i]] = false;
    }
  }
  int nf = 0;
  for (int i = 0; i < open.size(); ++i) {
    if (broken[open[i]]) {
      ++nf;
    }
  }
  int nb = open.size();
  for (int i = nf; i >= 0; --i) {
    sol[i] = fact[nb - i] * comb[nf][i];
    for (int j = i + 1; j <= nf; ++j) {
      sol[i] = sol[i] - sol[j] * comb[j][i] % 1000000007;
    }
    sol[i] = (sol[i] % 1000000007 + 1000000007) % 1000000007;
  }
  cout << sol[0] << endl;
  return 0;
}
