#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e9 + 10;
const long long linf = (long long)1e18 + 10;
const long long mod = (long long)(1e9 + 7);
const long long dx[] = {0, 1, 0, -1};
const long long dy[] = {1, 0, -1, 0};
const long long ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;
long long mop(long long a, long long b, long long m = mod) {
  long long r = 1;
  a %= m;
  for (; b; b >>= 1) {
    if (b & 1) r = r * a % m;
    a = a * a % m;
  }
  return r;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
bool ool(long long x, long long y, long long h, long long w) {
  return ((x < 0) || (h <= x) || (y < 0) || (w <= y));
}
bool deq(double a, double b) { return abs(a - b) < eps; }
struct oreno_initializer {
  oreno_initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
} oreno_initializer;
long long n, a[2020], b[2020], f[2020], m, k, res;
const long long MAXS = 2020;
long long fact[MAXS + 1], factr[MAXS + 1], inv[MAXS + 1];
long long comb(long long n, long long r) {
  if (fact[0] == 0) {
    fact[0] = factr[0] = inv[1] = 1;
    for (long long i = 2; i <= MAXS; i++)
      inv[i] = inv[mod % i] * (mod - mod / i) % mod;
    for (long long i = 1; i <= MAXS; i++)
      fact[i] = fact[i - 1] * i % mod, factr[i] = factr[i - 1] * inv[i] % mod;
  }
  if (r < 0 || n < r) return 0;
  return fact[n] * factr[r] % mod * factr[n - r] % mod;
}
signed main() {
  f[0] = 1;
  for (long long(i) = (1); (i) < (2020); ++(i)) f[i] = f[i - 1] * i % mod;
  cin >> n;
  for (long long(i) = (0); (i) < (n); ++(i)) {
    cin >> a[i];
    if (a[i] != -1)
      b[a[i] - 1] = 1;
    else
      k++;
  }
  for (long long(i) = (0); (i) < (n); ++(i))
    if (!b[i] && a[i] == -1) m++;
  for (long long(i) = (0); (i) < (m + 1); ++(i))
    (res += comb(m, i) * f[k - i] * (i % 2 ? -1 : 1)) %= mod;
  (res += mod) %= mod;
  cout << res << endl;
}
