#include <bits/stdc++.h>
using namespace std;
const long long maxn = 3e3 + 1;
const long long maxx = 1e13;
const long long mod = 1e9 + 7;
const long long mod1 = 998244353;
vector<long long> adj[maxn];
set<long long> adj1[maxn];
long long n, m, e, k;
long long d = 0;
priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
               greater<pair<long long, long long>>>
    q;
map<long long, map<long long, long long>> mp;
long long a[maxn];
long long dp1[maxn];
long long mu(long long x, long long power) {
  if (power == 0) return 1;
  if (power == 1) return x % mod;
  long long t = mu(x, power / 2) % mod;
  if (power % 2 == 0)
    return t * t % mod;
  else
    return (t * t) % mod * x % mod;
}
long long dp[maxn][maxn];
long long dd[maxn];
long long f(long long n, long long k) {
  if (dp[n][k] != -1) return dp[n][k];
  if (k == 1) return (n % mod * dp1[n] % mod) % mod;
  if (k == 0) return (dp1[n] % mod);
  long long ans = (((k - 1) % mod * f(n + 1, k - 2)) % mod +
                   ((n) % mod * f(n, k - 1) % mod)) %
                  mod;
  return dp[n][k] = ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long dem = 0;
  for (int i = 1; i <= n; i++) {
    long long x;
    cin >> x;
    a[i] = x;
    if (x != -1) dd[x] = 1;
  }
  dp1[0] = 1;
  for (int i = 1; i <= 2003; i++) {
    dp1[i] = (dp1[i - 1] % mod * i % mod) % mod;
  }
  long long cur = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] == -1) {
      if (dd[i])
        cur++;
      else
        dem++;
    }
  }
  memset(dp, -1, sizeof(dp));
  cout << f(cur, dem);
}
