#include <bits/stdc++.h>
using namespace std;
const int lmt = 2e3 + 3;
const long long mod = 1e9 + 7;
long long dp[lmt][lmt];
int main() {
  ios_base::sync_with_stdio(false);
  dp[2][2] = 1, dp[2][1] = 1, dp[2][0] = 2;
  for (int i = 3; i < lmt; i++) {
    for (int sem = 0; sem <= i; sem++) {
      if (sem > 0) {
        dp[i][sem] =
            (dp[i][sem] + ((sem - 1) * (dp[i - 1][max(0, sem - 2)])) % mod) %
            mod;
      }
      dp[i][sem] =
          (dp[i][sem] + ((i - sem) * (dp[i - 1][max(sem - 1, 0)])) % mod) % mod;
    }
  }
  int n, k = 0;
  cin >> n;
  int a[n + 1];
  map<int, int> cnt;
  for (int i = 1; i <= n; i++) {
    cnt[i] = 1;
  }
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == -1) {
      cnt[i]++;
      k++;
    } else {
      cnt[a[i]]--;
    }
  }
  int sem = 0;
  for (int i = 1; i <= n; i++) {
    if (cnt[i] == 2) sem++;
  }
  cout << dp[k][sem] << "\n";
  return 0;
}
