#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
long long fac[2005], c[2005][2005];
int p[2005], a[2005], N, M = 0, K = 0;
int main() {
  scanf("%d", &N);
  for (int i = 1, x; i <= N; ++i) {
    scanf("%d", &x);
    if (x == i) {
      puts("0");
      exit(0);
    }
    if (x == -1) {
      ++M;
      continue;
    }
    p[i] = 1;
    a[x] = 1;
  }
  for (int i = 1; i <= N; ++i)
    if (!p[i] && !a[i]) ++K;
  fac[0] = 1;
  for (int i = 1; i <= N; ++i) fac[i] = fac[i - 1] * i % mod;
  for (int i = 0; i <= N; ++i) {
    c[i][0] = 1;
    for (int j = 1; j <= i; ++j)
      c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;
  }
  long long ans = 0, q = 1;
  ;
  for (int k = 0; k <= K; ++k, q *= -1) {
    ans += fac[M - k] * c[K][k] * q;
    ans %= mod;
  }
  printf("%I64d\n", (ans + mod) % mod);
  return 0;
}
