#include <bits/stdc++.h>
using namespace std;
int n, a[2005], lol, m;
bool pos[2005];
long long int dp[2005], fact = 1;
long long int derrangement(long long int num) {
  if (dp[num] != -1) return dp[num];
  long long int sum =
      ((long long int)(num - 1) * derrangement(num - 1)) % 1000000007;
  sum =
      (sum + ((long long int)(num - 1) * derrangement(num - 2)) % 1000000007) %
      1000000007;
  if (lol)
    sum = (sum + ((long long int)lol * derrangement(num - 1)) % 1000000007) %
          1000000007;
  return dp[num] = sum;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] > 0) pos[a[i]] = true;
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == -1 && !pos[i])
      m++;
    else if (a[i] == -1)
      lol++;
  }
  for (long long int i = 1; i <= lol; i++) fact = (fact * i) % 1000000007;
  memset(dp, -1, sizeof(dp));
  if (lol == 0)
    dp[1] = 0, dp[2] = 1;
  else
    dp[1] = (lol * fact) % 1000000007, dp[0] = fact;
  printf("%lld\n", derrangement(m));
  return 0;
}
