#include <bits/stdc++.h>
using namespace std;
const int T = 2010;
long long F[T], fix[T], taken[T], a[T], dp[T][T];
long long n, have, good, i, j;
int main() {
  dp[1][1] = 0;
  dp[1][0] = 1;
  dp[0][0] = 1;
  F[0] = 1;
  F[1] = 1;
  for (i = 2; i <= 2005; i++) F[i] = (long long)F[i - 1] * i % 1000000007ll;
  for (i = 2; i <= 2005; i++) {
    dp[i][0] = F[i];
    dp[i][1] = ((long long)dp[i - 1][0] * (i - 1)) % 1000000007ll;
    for (j = 2; j <= i; j++)
      dp[i][j] = ((long long)(j - 1) * dp[i - 1][j - 2] +
                  (long long)(i - j) * dp[i - 1][j - 1]) %
                 1000000007ll;
  }
  for (i = 1; i <= 0; i++) {
    for (j = 0; j <= i; j++) cout << dp[i][j] << " ";
    cout << endl;
  }
  cin >> n;
  have = n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] != -1) {
      taken[a[i]] = 1, have--, fix[i] = 1;
    }
  }
  good = have;
  for (i = 1; i <= n; i++)
    if (!taken[i])
      if (fix[i]) good--;
  cout << dp[have][good] << endl;
}
