#include <bits/stdc++.h>
using namespace std;
inline void sfr(int *a) {
  char c = 0;
  while (c < 33) c = fgetc(stdin);
  *a = 0;
  while (c > 33) {
    *a = *a * 10 + c - '0';
    c = fgetc(stdin);
  }
}
inline void sfp(int a) {
  char c[1000];
  sprintf(c, "%d", a);
  puts(c);
}
int A[2002];
int B[2002];
long long DP[2002];
inline int getcnt(int n, int k) {}
int main() {
  int n;
  cin >> n;
  ;
  int p = 0, q = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &A[i]);
    if (A[i] == -1) p++;
    B[A[i]] = 1;
  }
  for (int i = 0; i < n; i++) {
    if (B[i + 1] == 0 && A[i] == -1) q++;
  }
  p = p - q;
  DP[0] = 1;
  for (int i = 0; i < p; i++) DP[0] = (DP[0] * (i + 1)) % 1000000007;
  DP[1] = (p * DP[0]) % 1000000007;
  for (int i = 2; i < q + 1; i++) {
    DP[i] = ((i - 1) * (DP[i - 1] + DP[i - 2]) + p * DP[i - 1]) % 1000000007;
  }
  cout << DP[q] << endl;
}
