#include <bits/stdc++.h>
using namespace std;
const int mo = 1000000007, maxn = 2000 + 5;
int n, a[maxn], b[maxn];
long long F[maxn];
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    if (a[i] != -1) b[a[i]] = i;
  }
  int x = 0, y = 0;
  for (int i = 1; i <= n; ++i)
    if (b[i] == 0) {
      ++x;
      if (a[i] == -1) ++y;
    }
  F[0] = 1;
  for (int i = 1; i <= x - y; ++i) F[0] = F[0] * i % mo;
  F[1] = F[0] * (x - y) % mo;
  for (int i = 2; i <= y; ++i)
    F[i] = (F[i - 1] * (x - y + i - 1) + F[i - 2] * (i - 1)) % mo;
  cout << F[y] << endl;
  return 0;
}
