#include <bits/stdc++.h>
struct Complex {
  double x, y;
  Complex(double _x = 0.0, double _y = 0.0) : x(_x), y(_y) {}
};
Complex operator+(Complex a, Complex b) {
  return Complex(a.x + b.x, a.y + b.y);
}
Complex operator-(Complex a, Complex b) {
  return Complex(a.x - b.x, a.y - b.y);
}
Complex operator*(Complex a, Complex b) {
  return Complex(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);
}
using namespace std;
namespace POINT2 {
struct Point {
  double x, y;
  Point(double _x = 0.0, double _y = 0.0) : x(_x), y(_y) {}
};
Point operator+(Point a, Point b) { return Point(a.x + b.x, a.y + b.y); }
Point operator-(Point a, Point b) { return Point(a.x - b.x, a.y - b.y); }
Point operator*(Point a, Point b) { return a.x * b.x + a.y * b.y; }
double operator^(Point a, Point b) { return a.x * b.y - a.y * b.x; }
bool operator<(const Point &l, const Point &r) {
  return l.y < r.y || (l.y == r.y && l.x < r.x);
}
double dis2(Point a, Point b) {
  return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
double dis(Point a, Point b) {
  return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
}  // namespace POINT2
int n, a[4444];
long long dp[4444][4444], jie[4444];
bool appear[4444];
int main() {
  cin >> n;
  for (int i = 1; i <= (n); i++) {
    cin >> a[i];
    if (a[i] != -1) appear[a[i]] = true;
  }
  long long c1 = 0, c2 = 0;
  for (int i = 1; i <= (n); i++) {
    if (appear[i] == false) {
      if (a[i] != -1)
        c1++;
      else
        c2++;
    }
  }
  jie[0] = 1;
  for (int i = 1; i <= (n + 10); i++)
    jie[i] = (jie[i - 1] * (long long)i) % 1000000007ll;
  for (long long j = 0; j <= c2; j++)
    for (long long i = 0; i <= n / 2 + n + 2; i++) {
      if (j == 0) {
        dp[i][j] = jie[i];
        continue;
      }
      if (j - 1 >= 0) dp[i][j] += i * dp[i][j - 1] % 1000000007ll;
      dp[i][j] %= 1000000007ll;
      if (j - 2 >= 0) dp[i][j] += (j - 1) * dp[i + 1][j - 2] % 1000000007ll;
      dp[i][j] %= 1000000007ll;
    }
  cout << dp[c1][c2] << endl;
  return 0;
}
