#include <bits/stdc++.h>
const int mod = 1000000007;
int comb[2010][2010];
long long fac[2010];
int add(int a, int b) { return ((long long)a + b) % mod; }
int main() {
  comb[0][0] = 1;
  for (int i = 1; i < 2010; i++) {
    comb[i][0] = 1;
    for (int j = 1; j <= i; j++) {
      comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];
      comb[i][j] %= mod;
    }
  }
  fac[0] = 1;
  for (int i = 1; i < 2010; i++) {
    fac[i] = fac[i - 1] * i % mod;
  }
  int n;
  scanf("%d", &n);
  int a[101010], s = 0, t = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == -1) {
      ++s;
    } else if (a[a[i] - 1] == -1) {
      ++t;
    }
  }
  long long ans = 0;
  int sgn = 1;
  for (int i = 0; i <= s - t; i++) {
    ans += sgn * fac[s - i] * comb[s - t][i] % mod;
    ans = (ans % mod + mod) % mod;
    sgn *= -1;
  }
  printf("%d\n", (int)ans);
  return 0;
}
