#include <bits/stdc++.h>
using namespace std;
const int N = 2009, mod = 1e9 + 7;
int v[N], a[N], n;
long long dp[N][N], ar[N];
long long dfs(int x, int y) {
  long long &d = dp[x][y];
  if (d + 1) return d;
  if (x) {
    long long ad = x - 1 ? (dfs(x - 2, y + 1) * (x - 1)) % mod : 0;
    if (y)
      return d = (ad + dfs(x - 1, y) * y % mod) % mod;
    else
      return d = ad;
  } else
    return d = ar[y];
}
int main() {
  cin >> n;
  int miss = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] + 1)
      v[a[i]] = 1;
    else
      miss++;
  }
  int bug = 0;
  for (int i = 1; i <= n; i++)
    if (v[i] == 0 && a[i] == -1) bug++;
  memset(dp, -1, sizeof(dp));
  ar[1] = 1;
  for (int i = 2; i < N; i++) ar[i] = (ar[i - 1] * i) % mod;
  cout << dfs(bug, miss - bug) << endl;
  return 0;
}
