#include <bits/stdc++.h>
enum { n_max = 2200, M = 1000000007 };
int A[n_max];
template <typename T>
void checkmin(T &a, T b) {
  if (a > b) a = b;
}
template <typename T>
T gcd(T a, T b) {
  while (b) {
    T c = a % b;
    a = b;
    b = c;
  }
  return a;
}
bool X[n_max];
long long D[n_max][n_max];
long long dyn(int e, int c) {
  if (D[e][c] != -1)
    return D[e][c];
  else if (c == 1 && e == 1)
    D[e][c] = 0;
  else if (c > 1 && c == e)
    D[e][c] = dyn(e - 1, c - 2) * (c - 1) % M;
  else if (c == 1)
    D[e][c] = dyn(e - 1, c - 1) * (e - c);
  else if (c)
    D[e][c] = (dyn(e - 1, c - 1) * (e - c) + dyn(e - 1, c - 2) * (c - 1)) % M;
  else if (e)
    D[e][c] = dyn(e - 1, c) * e % M;
  else
    D[e][c] = 1;
  return D[e][c];
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < (n); ++i) scanf("%d", A + i);
  for (int i = 0; i < (n); ++i) X[A[i] - 1] = 1;
  int e = 0, c = 0;
  for (int i = 0; i < (n); ++i)
    if (!X[i]) {
      e++;
      if (A[i] == -1) c++;
    }
  memset(D, -1, sizeof D);
  printf("%d\n", dyn(e, c));
  return 0;
}
