#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
long long int fac(long long int num) {
  if (num == 0) return 0;
  long long int ret = 1;
  while (num) {
    ret = (ret * num) % mod;
    num--;
  }
  return ret;
}
int main() {
  long long int i, t, j, tmp, n, m, k, cnt, fl, ind, st;
  cin >> n;
  vector<long long int> ar(n), val(n, 0);
  cnt = 0;
  for (i = 0; i < n; i++) {
    cin >> ar[i];
    if (ar[i] != -1) {
      ar[i]--;
      val[ar[i]] = 1;
      cnt++;
    }
  }
  m = 0;
  for (i = 0; i < n; i++) {
    if (ar[i] < 0 and val[i] == 0) m++;
  }
  vector<long long int> dp(m + 1);
  n = n - cnt - m;
  dp[0] = fac(n);
  dp[1] = (fac(n) * n) % mod;
  if (n == 0) {
    st = 3;
    dp[2] = 1;
  } else {
    st = 2;
  }
  for (i = st; i < m + 1; i++) {
    tmp = ((i + n - 1) * dp[i - 1]) % mod;
    tmp = (tmp + ((i - 1) * dp[i - 2])) % mod;
    dp[i] = tmp;
  }
  cout << dp[m] << endl;
}
