#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2020, P = 1e9 + 7;
int n, a[MAXN];
bool present[MAXN];
long long d[MAXN];
int main() {
  scanf("%d", &n);
  int cp = 0, ca = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    present[a[i]] = a[i] != -1;
  }
  for (int i = 1; i <= n; i++)
    if (a[i] == -1) {
      if (present[i])
        cp++;
      else
        ca++;
    }
  d[0] = 1;
  for (int i = 1; i <= cp; i++) d[0] = d[0] * i % P;
  d[1] = cp * d[0];
  for (int i = 2; i <= ca; i++)
    d[i] = (cp * d[i - 1] + (i - 1) * (d[i - 2] + d[i - 1])) % P;
  printf("%lld\n", d[ca]);
}
