#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
const int M = 101;
const double EPS = 1e-9;
const int INF = 1e9;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
double getDist(complex<double> a, complex<double> b) {
  return sqrt((a.real() - b.real()) * (a.real() - b.real()) +
              (a.imag() - b.imag()) * (a.imag() - b.imag()));
}
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }
long long mod = 1000000007, fib[N];
long long power(long long base, int p) {
  if (!p) return 1;
  long long ret = power(base, p / 2);
  ret *= ret;
  ret %= mod;
  if (p & 1) ret *= base, ret %= mod;
  return ret;
}
long long modInverse(int a) { return power(a, mod - 2); }
long long ncr(int n, int r) {
  return (((fib[n] * modInverse(fib[r])) % mod) * modInverse(fib[n - r])) % mod;
}
bool emty[N], taken[N];
int main() {
  fib[0] = fib[1] = 1;
  for (int i = 2; i < N; i++) fib[i] = (fib[i - 1] * i) % mod;
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int a;
    scanf("%d", &a);
    if (a == -1)
      emty[i] = 1;
    else
      taken[a] = 1;
  }
  int k = 0, total = 0;
  for (int i = 1; i <= n; i++) {
    if (taken[i] == 0 && emty[i] == 1) k++;
    total += emty[i];
  }
  long long sol = 0;
  for (int i = 0; i <= k; i++) {
    if (i & 1)
      sol -= (ncr(k, i) * fib[total - i]) % mod, sol += mod, sol %= mod;
    else
      sol += (ncr(k, i) * fib[total - i]) % mod;
  }
  cout << sol % mod;
  return 0;
}
