#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
inline int fastMax(int x, int y) {
  return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y;
}
inline int fastMin(int x, int y) {
  return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x;
}
const int maxn = 2000 + 100;
int a[maxn];
int ans[maxn];
bool used[maxn][2 * maxn];
int mas[maxn][2 * maxn];
long long fact[maxn * 2];
bool u[maxn];
int n;
const int inf = 1000000001;
const int MANY = 1000000007;
long long f(int n, int k) {
  if (n < k) return 0;
  if (n == k) {
    return fact[k];
  } else {
    if (used[n][k]) return mas[n][k];
    used[n][k] = 1;
    return mas[n][k] = ((n - k - 1) * f(n - 1, k + 1) + k * f(n - 1, k)) % MANY;
  }
}
int main() {
  ios::sync_with_stdio(false);
  fact[0] = 1;
  for (int i = 1; i < 2 * maxn; i++) {
    fact[i] = i * fact[i - 1];
    fact[i] %= MANY;
  }
  cin >> n;
  int num = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == -1) num++;
    u[a[i]] = 1;
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (!u[i] && a[i] != -1) cnt++;
  }
  cout << f(num, cnt) << endl;
  return 0;
  n = 4;
  for (n = 1; n <= 10; n++) {
    cerr << n << endl;
    cout << n << " " << f(n, 0) << endl;
  }
  return 0;
}
