#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2010;
const long long mod = 1e9 + 7;
long long n, x, y, a[MAXN], b[MAXN], dp[MAXN], fac[MAXN];
void work() {
  scanf("%lld", &n);
  for (register long long i = 1; i <= n; ++i) {
    scanf("%lld", &a[i]);
    if (a[i] != -1) b[a[i]] = 1;
  }
  for (register long long i = 1; i <= n; ++i) {
    if (a[i] == -1 && b[i] > 0) ++x;
    if (a[i] == -1 && b[i] == 0) ++y;
  }
  dp[0] = fac[x];
  for (register long long i = 1; i <= y; ++i) {
    dp[i] = (x * dp[i - 1] + (i - 1) * dp[i - 1]) % mod;
    if (i > 1) dp[i] = (dp[i] + (i - 1) * dp[i - 2]) % mod;
  }
  printf("%lld\n", dp[y]);
}
signed main() {
  long long _ = 1;
  fac[1] = fac[0] = 1;
  for (register long long i = 2; i <= MAXN - 10; ++i)
    fac[i] = 1ll * fac[i - 1] * i % mod;
  while (_--) work();
  return 0;
}
