#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v) {
  o << "{";
  for (long long i = 0; i < (long long)v.size(); i++)
    o << (i > 0 ? ", " : "") << v[i];
  o << "}";
  return o;
}
long long n, x, a;
const long long CMAX = 10000000;
long long fact[CMAX] = {};
long long revFact[CMAX] = {};
void setFact(long long N) {
  fact[0] = 1;
  for (long long i = 1; i < N; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= mod;
  }
  revFact[N - 1] = powmod(fact[N - 1], mod - 2);
  for (long long i = N - 2; i >= 0; i--) {
    revFact[i] = revFact[i + 1] * (i + 1);
    revFact[i] %= mod;
  }
}
long long getC(long long a, long long b) {
  return (((fact[a] * revFact[b]) % mod) * revFact[a - b]) % mod;
}
long long kc[3000];
long long b[3000];
long long c = 0;
long long d = 0;
signed main() {
  std::cin >> n;
  setFact(n * 3);
  for (long long i = 0; i < n; i++) {
    std::cin >> kc[i];
    if (kc[i] != -1)
      b[kc[i] - 1] = 1;
    else
      c++;
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++)
    if (!b[i] && kc[i] == -1) d++;
  for (long long i = 0; i < d + 1; i++) {
    (ans += getC(d, i) * fact[c - i] * (i % 2 ? -1 : 1)) %= mod;
  }
  (ans += mod) %= mod;
  std::cout << ans << '\n';
}
