#include <bits/stdc++.h>
using namespace std;
int mod = 1000000007;
vector<bool> pos(2005, false), num(2005, false);
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k1 = 0, k2 = 0, i, x;
  cin >> n;
  int a[n];
  long long dp[n];
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] != -1) {
      pos[i] = true;
      num[a[i]] = true;
      k2++;
    }
  }
  k2 = n - k2;
  for (i = 1; i <= n; i++) {
    if (!pos[i] && !num[i]) k1++;
  }
  k2 -= k1;
  dp[0] = 1;
  for (i = 1; i <= k2; i++) dp[0] = (dp[0] * i) % mod;
  for (i = 1; i <= k1; i++) {
    dp[i] = (k2 * dp[i - 1]) % mod;
    if (i > 1)
      dp[i] = (dp[i] + ((i - 1) * (dp[i - 1] + dp[i - 2])) % mod) % mod;
  }
  cout << dp[k1];
}
