#include <bits/stdc++.h>
using namespace std;
long long C[2222][2222];
long long fac[2222];
int n;
int a[2222];
int check[2222];
void process() {
  memset(check, -1, sizeof check);
  for (int j = 0, _b = n; j <= _b; j++) C[0][j] = 1;
  fac[0] = 1;
  for (int j = 1, _b = n; j <= _b; j++) {
    for (int i = 1, _b = j; i <= _b; i++)
      C[i][j] = (C[i - 1][j - 1] + C[i][j - 1]) % 1000000007;
    fac[j] = (fac[j - 1] * j) % 1000000007;
  }
  int s = 0;
  int t = 0;
  long long res = 0;
  for (int i = 1, _b = n; i <= _b; i++) check[a[i]] = 1;
  for (int i = 1, _b = n; i <= _b; i++) {
    if (a[i] == -1 && check[i] == -1) s++;
    if (a[i] == -1) t++;
  }
  res = fac[t];
  for (int i = 1, _b = s; i <= _b; i++) {
    int sign = 1;
    if (i % 2 == 1) sign = -1;
    long long tmp = (C[i][s] * fac[t - i]) % 1000000007;
    res = (res + sign * tmp + 1000000007) % 1000000007;
  }
  cout << res << endl;
}
int main() {
  scanf("%d", &n);
  for (int i = 1, _b = n; i <= _b; i++) scanf("%d", &a[i]);
  process();
  return 0;
}
