#include <bits/stdc++.h>
using namespace std;
long long dp[2003][2003];
int A[10000];
bool done[2003];
int n;
long long fact[2002];
long long func(int lft, int cnt) {
  if (cnt == 0) {
    return fact[lft];
  }
  if (dp[lft][cnt] != -1) return dp[lft][cnt];
  long long ans = 0;
  {
    if (cnt > 1) ans += ((cnt - 1) * func(lft - 1, cnt - 2)) % 1000000007;
    if (lft - cnt > 0)
      ans += ((lft - cnt) * func(lft - 1, cnt - 1)) % 1000000007;
  }
  ans = ans % 1000000007;
  return (dp[lft][cnt] = ans);
}
int main() {
  fact[0] = 1;
  for (long long i = 1; i <= 2000; i++)
    fact[i] = (fact[i - 1] * i) % 1000000007;
  int lft = 0;
  memset(dp, -1, sizeof(dp));
  memset(done, false, sizeof(done));
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
    if (A[i] != -1)
      done[A[i]] = true;
    else
      lft++;
  }
  dp[0][0] = 0;
  dp[1][0] = 1;
  dp[1][1] = 0;
  dp[2][1] = 1;
  for (int i = 0; i <= n; i++)
    for (int j = i + 1; j <= n; j++) dp[i][j] = 0;
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    if (!done[i] && A[i] == -1) cnt++;
  cout << func(lft, cnt) << endl;
  return 0;
}
