#include <bits/stdc++.h>
const int MOD = 1000000007;
const int MAXN = 2005;
int N, tot = 0, fixed = 0, A[MAXN], C[MAXN][MAXN], F[MAXN], Fac[MAXN];
bool flag[MAXN] = {0};
void init();
int main() {
  scanf("%d", &N);
  int i, j;
  for (i = 1; i <= N; i++) {
    scanf("%d", &A[i]);
    if (A[i] == -1)
      tot++;
    else
      flag[A[i]] = true;
  }
  for (i = 1; i <= N; i++)
    if (A[i] == -1 && !flag[i]) fixed++;
  init();
  for (i = fixed; i >= 0; i--) {
    F[i] = (long long)C[fixed][i] * Fac[tot - i] % MOD;
    for (j = i + 1; j <= fixed; j++)
      F[i] = (F[i] - (long long)C[j][i] * F[j] % MOD + MOD) % MOD;
  }
  printf("%d\n", F[0]);
  return 0;
}
void init() {
  C[0][0] = 1;
  int i, j;
  for (i = 1; i <= fixed; i++) {
    C[i][0] = 1;
    for (j = 1; j <= i; j++)
      C[i][j] = ((long long)C[i - 1][j] + C[i - 1][j - 1]) % MOD;
  }
  for (i = Fac[0] = 1; i <= tot; i++) Fac[i] = (long long)i * Fac[i - 1] % MOD;
}
