#include <bits/stdc++.h>
using namespace std;
long long permutation[2005];
long long nCr[2005][2005];
bool frees[2005];
bool have[2005];
int n_free;
int left1;
long long cal() {
  int n = left1;
  long long res = permutation[n];
  long long sign = -1;
  for (int i = 1; i <= n - n_free; i++) {
    long long temp = sign * nCr[n - n_free][i];
    temp %= 1000000007;
    temp *= permutation[n - i];
    temp = (temp + 1000000007) % 1000000007;
    res += temp;
    res %= 1000000007;
    sign *= -1;
  }
  return res;
}
int main() {
  permutation[0] = 1;
  for (int i = 1; i < 2005; i++) {
    permutation[i] = i * permutation[i - 1];
    permutation[i] %= 1000000007;
  }
  nCr[0][0] = nCr[1][0] = nCr[1][1] = 1LL;
  for (int i = 2; i < 2005; i++) {
    nCr[i][0] = nCr[i][i] = 1;
    for (int j = 1; j < i; j++) {
      nCr[i][j] = nCr[i - 1][j - 1] + nCr[i - 1][j];
      nCr[i][j] %= 1000000007;
    }
  }
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    if (a == -1) {
      left1++;
    } else {
      frees[i + 1] = true;
      have[a] = true;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (frees[i] && !have[i]) {
      n_free++;
    }
  }
  cout << cal() << endl;
  return 0;
}
