#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long fc[100100], fi[100100], dir1[100100], dir2[100100], n, num1, num2, t;
long long f(long long a, long long b) {
  long long ans = 1;
  a %= mod;
  while (b) {
    if (b & 1) ans = ans * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ans;
}
void init() {
  fc[0] = 1;
  for (long long i = 1; i < 3000; i++) fc[i] = fc[i - 1] * i % mod;
  fi[2500] = f(fc[2500], mod - 2);
  for (long long i = 2500; i >= 1; i--) fi[i - 1] = fi[i] * i % mod;
}
long long c(long long n, long long m) {
  if (n < m) return 0;
  return fc[n] * fi[m] % mod * fi[n - m] % mod;
}
int main() {
  init();
  scanf("%lld", &n);
  for (long long i = 0; i < n; i++) {
    scanf("%lld", &t);
    if (t == -1)
      num1++, dir1[i + 1] = 1;
    else
      dir2[t] = 1;
  }
  for (int i = 1; i <= n; i++)
    if (!dir2[i] && dir1[i]) num2++;
  long long ans = 0;
  for (int i = 0, t = 1; i <= num2; i++, t *= -1) {
    ans = (mod + ans + t * c(num2, i) * fc[num1 - i]) % mod;
  }
  printf("%lld\n", ans);
  return 0;
}
