#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long m, a, b, c, temp, x, y;
const int MAXN = 1e5 + 11, mod = 1e9 + 7;
long long max(long long a, long long b) { return ((a > b) ? a : b); }
long long min(long long a, long long b) { return ((a > b) ? b : a); }
vector<long long> read(int n) {
  vector<long long> v(n);
  for (int i = 0; i < v.size(); i++) cin >> v[i];
  return v;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long dp[4000][2001], fac[MAXN];
bool vis[4000][2001];
long long rec(long long n, long long k) {
  if (k == 0) return fac[n];
  if (k == 1) return (n * fac[n]) % mod;
  if (vis[n][k]) return dp[n][k];
  vis[n][k] = true;
  return dp[n][k] =
             (((k - 1) * rec(n + 1, k - 2)) % mod + (n * rec(n, k - 1)) % mod) %
             mod;
}
void sol(void) {
  fac[0] = 1;
  for (int i = 1; i < MAXN; i++) fac[i] = fac[i - 1] * i % mod;
  int n;
  cin >> n;
  vector<long long> v = read(n);
  int cntk = 0;
  int cntn = 0;
  set<int> rem;
  set<int> pos;
  for (int i = 1; i <= n; i++) rem.insert(i), pos.insert(i);
  for (int i = 0; i < n; i++) {
    rem.erase(v[i]);
    if (v[i] != -1) pos.erase(i + 1);
  }
  for (int i = 1; i <= n; i++) {
    if (rem.count(i) && pos.count(i))
      cntk++;
    else if (rem.count(i))
      cntn++;
  }
  cout << rec(cntn, cntk);
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int test = 1;
  for (int i = 1; i <= test; i++) sol();
}
