#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000007LL;
const int NMax = 2010;
int N, A[NMax], have[NMax], have1[NMax];
long long C[NMax][NMax], fac[NMax];
long long D[NMax];
int main() {
  scanf("%d", &N);
  fac[0] = 1;
  for (int i = 1; i <= N; i++) fac[i] = (fac[i - 1] * (long long)i) % INF;
  C[0][0] = 1;
  for (int i = 1; i <= N; i++) {
    C[i][0] = 1;
    for (int j = 1; j <= i; j++)
      C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % INF;
  }
  for (int i = 1; i <= N; i++) {
    scanf("%d", A + i);
    if (A[i] == i) {
      puts("0");
      getchar();
      getchar();
      return 0;
    }
    if (A[i] != -1) {
      have[A[i]] = 1;
      have1[i] = 1;
    }
  }
  int cnt1 = 0, cnt2 = 0;
  for (int i = 1; i <= N; i++)
    if (!have[i]) {
      cnt2++;
      if (!have1[i]) cnt1++;
    }
  for (int j = 0; j <= cnt2; j++) {
    long long tmp = 0;
    for (int i = 0; i <= j; i++) {
      if (i % 2 == 0)
        tmp = (tmp + C[j][i] * fac[j - i] % INF) % INF;
      else
        tmp = (tmp - C[j][i] * fac[j - i] % INF + INF) % INF;
    }
    D[j] = tmp;
  }
  long long ret = 0;
  for (int i = cnt1; i <= cnt2; i++)
    ret = (ret + C[cnt2 - cnt1][i - cnt1] * D[i] % INF) % INF;
  printf("%I64d\n", ret);
  getchar();
  getchar();
  return 0;
}
