#include <bits/stdc++.h>
using namespace std;
const int maxn = 2010;
const int mod = 1000000007;
int a[maxn], in[maxn], vis[maxn][maxn];
long long fac[2 * maxn], dp[maxn][maxn];
void init() {
  fac[0] = 1;
  for (int i = 1; i < 2 * maxn; i++) {
    fac[i] = (i * fac[i - 1]) % mod;
  }
}
long long solve(int n, int k) {
  if (vis[n][k]) return dp[n][k];
  vis[n][k] = 1;
  if (k == 0) {
    return dp[n][k] = fac[n];
  }
  if (k == 1) {
    return dp[n][k] = (n * fac[n]) % mod;
  }
  return dp[n][k] = (n * solve(n, k - 1) + (k - 1) * solve(n + 1, k - 2)) % mod;
}
int main() {
  int t, n, k;
  init();
  scanf("%d", &t);
  for (int i = 1; i <= t; i++) {
    scanf("%d", &a[i]);
    if (a[i] > 0) in[a[i]] = 1;
  }
  n = k = 0;
  for (int i = 1; i <= t; i++) {
    if (!in[i]) {
      if (a[i] > 0)
        ++n;
      else
        ++k;
    }
  }
  printf("%lld\n", solve(n, k));
  return 0;
}
