#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
int b1[maxn], b2[maxn];
int N, n, m;
int a[maxn];
long long C[maxn][maxn];
long long fac[maxn];
void Pre() {
  C[1][1] = 1;
  for (int i = 2; i <= 2000; i++) {
    C[i][1] = i;
    C[i][i] = 1;
    for (int j = 2; j < i; j++) {
      C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
      C[i][j] %= 1000000007;
    }
  }
  fac[0] = 1;
  for (int i = 1; i <= 2000; i++) fac[i] = fac[i - 1] * i % 1000000007;
}
int main() {
  Pre();
  while (scanf("%d", &N) == 1) {
    memset(b1, 0, sizeof(b1));
    memset(b2, 0, sizeof(b2));
    n = N;
    for (int i = 1; i <= N; i++) {
      scanf("%d", a + i);
      if (a[i] != -1) {
        b1[i] = 1;
        b2[a[i]] = 1;
        n--;
      }
    }
    m = 0;
    for (int i = 1; i <= N; i++)
      if (!b1[i] && !b2[i]) m++;
    long long ans = fac[n];
    long long coe = -1;
    for (int i = 1; i <= m; i++) {
      ans = ans + coe * C[m][i] * fac[n - i] % 1000000007;
      ans = (ans % 1000000007 + 1000000007) % 1000000007;
      coe = -coe;
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
