#include <bits/stdc++.h>
using namespace std;
long long n, arr[2001], dp[2001][2001];
bool oc[2001], use[2001];
long long fact[2001];
long long rec(int ev, int fixp) {
  if (fixp == 0) return fact[ev];
  if (fixp == 1) return (ev * fact[ev]) % 1000000007;
  if (~dp[ev][fixp]) return dp[ev][fixp];
  dp[ev][fixp] = (((ev * rec(ev, fixp - 1)) % 1000000007) +
                  ((fixp - 1) * rec(ev + 1, fixp - 2)) % 1000000007) %
                 1000000007;
  return dp[ev][fixp];
}
int main() {
  cin >> n;
  memset((dp), (-1), sizeof(dp));
  int k = 0, cnt = 0;
  fact[0] = 1;
  for (int i = 0; i < n; i++) {
    fact[i + 1] = (fact[i] * (i + 1)) % 1000000007;
    cin >> arr[i];
    if (arr[i] == -1) {
      cnt++;
      continue;
    }
    use[arr[i] - 1] = 1;
    oc[i] = 1;
  }
  for (int i = 0; i < n; i++)
    if (oc[i] == 0 && use[i] == 0) k++;
  cout << rec(cnt - k, k);
  return 0;
}
