#include <bits/stdc++.h>
using namespace std;
long long n;
long long a[2005], f[2005];
long long cnt, x, y;
signed main() {
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    if (a[i] == -1) cnt++;
  }
  for (long long i = 1; i <= n; i++) {
    if (a[i] > 0) {
      if (a[a[i]] == -1) x++;
    }
  }
  y = cnt - x;
  f[0] = 1;
  for (long long i = 2; i <= x; i++) {
    f[0] = f[0] * i % 1000000007;
  }
  for (long long i = 1; i <= y; i++) {
    f[i] = ((x + i - 1) * f[i - 1]) % 1000000007;
    if (i > 1) f[i] = (f[i] + (i - 1) * f[i - 2]) % 1000000007;
  }
  printf("%lld", f[y]);
  return 0;
}
