#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7, maxn = 2000;
long long n, a[maxn + 5], b[maxn + 5], jc[maxn + 5], jcn[maxn + 5], sum, sum2,
    ans;
long long ksm(long long a, long long n) {
  long long base = a;
  long long ans = 1;
  while (n) {
    if (n & 1) ans = ans * base % mod;
    n >>= 1;
    base = base * base % mod;
  }
  return ans % mod;
}
void init() {
  jc[0] = 1;
  for (long long i = 1; i <= maxn; i++) jc[i] = jc[i - 1] * i % mod;
  jcn[maxn] = ksm(jc[maxn], mod - 2);
  for (long long i = maxn - 1; i >= 0; i--) jcn[i] = jcn[i + 1] * (i + 1) % mod;
}
long long C(long long n, long long m) {
  if (m > n) return 0;
  return ((jc[n] * jcn[m]) % mod * jcn[n - m]) % mod;
}
signed main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] != -1)
      b[a[i]] = 1;
    else
      sum++;
  }
  for (long long i = 1; i <= n; i++)
    if (a[i] == -1 && b[i]) sum2++;
  init();
  ans = jc[sum];
  for (long long i = 1; i <= sum; i++) {
    long long pans = C(sum - sum2, i) * jc[sum - i] % mod;
    if (i & 1)
      ans = (ans - pans + mod) % mod;
    else
      ans = (ans + pans) % mod;
  }
  cout << ans;
  return 0;
}
