#include <bits/stdc++.h>
const int ee = 1000000007;
int a[2005], n, m = 0, k = 0, v[2005] = {0}, i, t;
long long r = 0, rt;
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] != -1) {
      m++;
      v[a[i]] = 1;
    }
  }
  for (i = 1; i <= n; i++) {
    if (a[i] != -1 && v[i] == 0) k++;
  }
  for (t = 0; t <= n - m - k; t++) {
    rt = (t % 2 == 0 ? 1 : -1);
    for (i = n - m - t; i >= n - m - k - t + 1; i--) rt = rt * i % ee;
    for (i = n - m - k; i >= t + 1; i--) rt = rt * i % ee;
    r = (r + rt) % ee;
  }
  r = (r + ee) % ee;
  printf("%I64d\n", r);
  return 0;
}
