#include <bits/stdc++.h>
long long A[2005], C[2005][2005], F[2005][2005], U[2005], N, X, Y;
using namespace std;
int main() {
  F[0][0] = 1;
  for (int i = 1; i < 2005; i++) F[i][0] = (F[i - 1][0] * i) % 1000000007;
  for (int i = 0; i < 2005; i++) {
    C[i][0] = 1;
    for (int j = 1; j < i + 1; j++) C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
  }
  cin >> N;
  for (int i = 1; i < N + 1; i++) {
    cin >> A[i];
    if (A[i] > 0) U[A[i]] = 1;
  }
  for (int i = 1; i < N + 1; i++)
    if (A[i] == -1) X++, Y += !U[i];
  for (int a = 1; a < X + 1; a++) {
    F[a][1] = ((a - 1) * F[a - 1][0]) % 1000000007;
    for (int b = 2; b < a + 1; b++)
      F[a][b] =
          ((b - 1) * F[a - 1][b - 2] + (a - b) * F[a - 1][b - 1]) % 1000000007;
  }
  cout << F[X][Y];
}
