#include <bits/stdc++.h>
using namespace std;
const long long P = (long long)1e9 + 7;
const int MAXN = 2000 + 10;
int len;
int p[MAXN];
int use[MAXN];
int n, k;
long long dp[MAXN][MAXN];
long long fact[MAXN];
int main() {
  cin >> len;
  n = 0, k = 0;
  memset(use, 0, sizeof(use));
  for (int i = int(1); i < int(len + 1); ++i) {
    scanf("%d", &p[i]);
    if (p[i] == -1)
      n++;
    else
      use[p[i]] = true;
  }
  for (int i = int(1); i < int(len + 1); ++i)
    if ((!use[i]) && p[i] == -1) k++;
  fact[0] = 1;
  dp[0][0] = 1;
  for (int i = int(1); i < int(n + 1); ++i) {
    fact[i] = (fact[i - 1] * i) % P;
    dp[i][0] = 1;
  }
  for (int j = int(1); j < int(k + 1); ++j)
    for (int i = int(j); i < int(n + 1); ++i) {
      dp[i][j] = 0;
      if (i > j) dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] * (i - j)) % P;
      if (j > 1)
        dp[i][j] = (dp[i][j] + dp[i - 1][j - 2] * (j - 1) * (i - j + 1)) % P;
    }
  cout << (dp[n][k] * fact[n - k]) % P << '\n';
  return 0;
}
