#include <bits/stdc++.h>
using namespace std;
int n;
int A[2005], C[2005][2005], F[2005], apare[2005];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &A[i]);
    if (A[i] != -1) apare[A[i]] = 1;
  }
  C[1][0] = C[1][1] = 1;
  for (int i = 2; i <= n; ++i) {
    C[i][0] = 1;
    for (int j = 1; j <= i; ++j) {
      C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
      if (C[i][j] >= 1000000007) C[i][j] -= 1000000007;
    }
  }
  F[0] = 1;
  for (int i = 1; i <= n; ++i) {
    F[i] = (1LL * i * F[i - 1]) % 1000000007;
  }
  int total = 0, p = 0;
  for (int i = 1; i <= n; ++i) {
    if (A[i] == -1) {
      ++total;
    }
    if (!apare[i] && A[i] == -1) {
      ++p;
    }
  }
  int sol = F[total];
  for (int i = 1; i <= p; ++i) {
    int r = (1LL * C[p][i] * F[total - i]) % 1000000007;
    if (i & 1) {
      sol -= r;
      if (sol < 0) sol += 1000000007;
    } else {
      sol += r;
      if (sol >= 1000000007) sol -= 1000000007;
    }
  }
  printf("%d\n", sol);
  return 0;
}
