#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000 + 3;
const long long mod = 1e9 + 7;
int n;
int a[maxn];
bool used[maxn];
bool khali[maxn];
int Total = 0;
int Fixed = 0;
long long sol[maxn];
long long F[maxn];
long long c[maxn][maxn];
long long C(int n, int k) {
  if (k > n) return 0;
  if (k == n || k == 0) return 1LL;
  if (k == 1 || k == n - 1) return (long long)n % mod;
  if (c[n][k] == -1) c[n][k] = (C(n - 1, k) + C(n - 1, k - 1)) % mod;
  return c[n][k];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == -1) {
      khali[i] = true;
      Total++;
    } else {
      used[a[i]] = true;
    }
  }
  for (int x = 1; x <= n; x++) {
    if (used[x] == false) {
      if (khali[x] == true) {
        Fixed++;
      }
    }
  }
  memset(c, -1, sizeof c);
  F[0] = 1LL;
  for (int i = 1; i < maxn; i++) F[i] = (F[i - 1] * (long long)(i)) % mod;
  for (int cnt = Fixed; cnt >= 0; cnt--) {
    sol[cnt] = (C(Fixed, cnt) * 1LL * F[Total - cnt]) % mod;
    for (int x = cnt + 1; x <= Fixed; x++) {
      sol[cnt] = (sol[cnt] - (sol[x] * 1LL * C(x, cnt)) + mod) % mod;
    }
  }
  cout << sol[0] << endl;
  return 0;
}
