#include <bits/stdc++.h>
using namespace std;
long long modd = 1000000007;
long long pow(long long x, long long y) {
  long long ret(1);
  for (; y; y >>= 1) {
    if (y & 1) ret = ret * x % modd;
    x = x * x % modd;
  }
  return ret;
}
long long fac[3000], rfac[3000], ans;
int n, m, k, a[10000];
bool used[10000];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= (n); ++i) {
    scanf("%d", &a[i]);
    if (a[i] == -1)
      ++m;
    else
      used[a[i]] = true;
  }
  for (int i = 1; i <= (n); ++i)
    if (a[i] == -1 && !used[i]) ++k;
  fac[0] = 1;
  for (int i = 1; i <= (n); ++i) fac[i] = fac[i - 1] * i % modd;
  rfac[n] = pow(fac[n], modd - 2);
  for (int i = (n - 1); i >= (0); --i) rfac[i] = rfac[i + 1] * (i + 1) % modd;
  for (int i = (0); i <= (k); ++i) {
    long long t =
        fac[k] * rfac[i] % modd * rfac[k - i] % modd * fac[m - i] % modd;
    if (i & 1)
      ans = (ans + modd - t) % modd;
    else
      ans = (ans + t) % modd;
  }
  printf("%I64d\n", ans);
  return 0;
}
