#include <bits/stdc++.h>
const int N = 2000 + 5;
const int mod = 1000000007;
int s[N];
long long a[N];
long long c[N][N];
void init() {
  memset(c, 0, sizeof c);
  for (int i = 0; i < N; ++i) {
    c[i][i] = c[i][0] = 1;
    for (int j = 1; j < i; ++j) {
      c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
    }
  }
  a[0] = 1;
  for (int i = 1; i < N; i++) a[i] = a[i - 1] * i % mod;
}
int main() {
  init();
  int n;
  scanf("%d", &n);
  int tot = 0, cnt = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &s[i]);
    if (s[i] == -1) tot++;
  }
  for (int i = 1; i <= n; i++) {
    if (s[i] != -1 && s[s[i]] == -1) cnt++;
  }
  long long ans = a[tot];
  int wrong = tot - cnt;
  for (int i = 1; i <= wrong; i++) {
    if (i & 1)
      ans -= c[wrong][i] * a[tot - i];
    else
      ans += c[wrong][i] * a[tot - i];
    ans = (ans + mod) % mod;
  }
  printf("%I64d\n", ans);
}
