#include <bits/stdc++.h>
using namespace std;
const int N = 2002;
const int M = 123;
const double Pi = acos(-1);
const long long Inf = 1e18;
const int inf = 1e9;
const int mod = 1e9 + 7;
void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
int mult(int a, int b) { return 1ll * a * b % mod; }
int n, dp[N][N];
bool used[N], ok[N];
vector<int> a, b;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1, x; i <= n; i++) {
    cin >> x;
    if (x != -1) {
      used[x] = 1;
    } else {
      ok[i] = 1;
    }
  }
  int L = 0;
  for (int i = 1; i <= n; i++) {
    if (!used[i]) {
      a.push_back(i);
      L++;
    }
    if (ok[i]) {
      b.push_back(i);
    }
  }
  dp[0][0] = 1;
  memset(used, 0, sizeof used);
  memset(ok, 0, sizeof ok);
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  for (int i = 0; i < L; i++) {
    for (int j = 0; j <= i; j++) {
      add(dp[i + 1][j + (a[i] == b[i])], dp[i][j]);
      if (j > 0) {
        add(dp[i + 1][j - 1], mult(dp[i][j], j));
      }
      assert(ok[a[i]] + used[b[i]] < 2);
      if (ok[a[i]] + used[b[i]] == 1) {
        add(dp[i + 1][j + 1], dp[i][j]);
        add(dp[i + 1][j], mult(i - j - 1, dp[i][j]));
      } else {
        add(dp[i + 1][j], mult(i - j, dp[i][j]));
      }
    }
    used[a[i]] = ok[b[i]] = 1;
  }
  cout << dp[L][0] << endl;
  return 0;
}
