#include <bits/stdc++.h>
using namespace std;
long long C[2010][2010] = {{0}};
const long long MOD = 1000000007LL;
long long lst[2010] = {0};
long long fac[2010] = {0};
int label[2010] = {0};
int pos[2010] = {0};
void prep() {
  C[0][0] = 1;
  C[1][0] = C[1][1] = 1;
  for (int i = 1; i <= 2000; i++) {
    C[i][0] = 1, C[i][1] = i, C[i][i] = 1;
    for (int j = 2; j < i; j++) {
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;
    }
  }
  fac[0] = fac[1] = 1;
  for (int i = 2; i <= 2000; i++) {
    fac[i] = (fac[i - 1] * i) % MOD;
  }
}
long long modfix(long long num) { return (num % MOD + MOD) % MOD; }
int N = 0;
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> lst[i];
    if (lst[i] == -1) {
      pos[i + 1] = 1;
    } else {
      label[lst[i]] = 1;
    }
  }
  prep();
  long long freeval = 0, fixval = 0, sum = 0;
  for (int i = 1; i <= N; i++) {
    if (label[i] != 1) {
      if (pos[i] != 1) {
        freeval++;
      } else {
        fixval++;
      }
      sum++;
    }
  }
  long long res = 0;
  long long sym = 1;
  for (int i = 0; i <= fixval; i++) {
    res = res + modfix(fac[sum - i] * C[fixval][i] * sym);
    res = modfix(res);
    sym = sym * -1;
  }
  cout << res << endl;
  return 0;
}
