#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int a[2010];
int used[2010];
int n;
int main() {
  memset(used, 0, sizeof(used));
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] != -1) used[a[i]] = 1;
  }
  int m = 0;
  int n1 = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == -1 && !used[i + 1]) m++;
    if (a[i] == -1) n1++;
  }
  long long re = 0;
  long long fu = -1;
  for (int k = 0; k <= m; k++) {
    fu *= -1;
    long long temp = 1;
    for (long long i = k + 1; i <= m; i++) temp = (temp * i) % mod;
    for (long long i = m - k + 1; i <= n1 - k; i++) temp = (temp * i) % mod;
    re = (re + fu * temp) % mod;
  }
  cout << (re + mod) % mod << endl;
  return 0;
}
