#include <bits/stdc++.h>
using namespace std;
template <::std::uint_fast64_t mod>
class ModInt {
 private:
  using value_type = ::std::uint_fast64_t;
  value_type n;

 public:
  ModInt() : n(0) {}
  ModInt(value_type n_) : n(n_ % mod) {}
  ModInt(const ModInt& m) : n(m.n) {}
  template <typename T>
  explicit operator T() const {
    return static_cast<T>(n);
  }
  value_type get() const { return n; }
  friend ::std::ostream& operator<<(::std::ostream& os, const ModInt<mod>& a) {
    return os << a.n;
  }
  friend ::std::istream& operator>>(::std::istream& is, ModInt<mod>& a) {
    value_type x;
    is >> x;
    a = ModInt<mod>(x);
    return is;
  }
  bool operator==(const ModInt& m) const { return n == m.n; }
  bool operator!=(const ModInt& m) const { return n != m.n; }
  ModInt& operator*=(const ModInt& m) {
    n = n * m.n % mod;
    return *this;
  }
  ModInt pow(value_type b) const {
    ModInt ans = 1, m = ModInt(*this);
    while (b) {
      if (b & 1) ans *= m;
      m *= m;
      b >>= 1;
    }
    return ans;
  }
  ModInt inv() const { return (*this).pow(mod - 2); }
  ModInt& operator+=(const ModInt& m) {
    n += m.n;
    n = (n < mod ? n : n - mod);
    return *this;
  }
  ModInt& operator-=(const ModInt& m) {
    n += mod - m.n;
    n = (n < mod ? n : n - mod);
    return *this;
  }
  ModInt& operator/=(const ModInt& m) {
    *this *= m.inv();
    return *this;
  }
  ModInt operator+(const ModInt& m) const { return ModInt(*this) += m; }
  ModInt operator-(const ModInt& m) const { return ModInt(*this) -= m; }
  ModInt operator*(const ModInt& m) const { return ModInt(*this) *= m; }
  ModInt operator/(const ModInt& m) const { return ModInt(*this) /= m; }
  ModInt& operator++() {
    n += 1;
    return *this;
  }
  ModInt& operator--() {
    n -= 1;
    return *this;
  }
  ModInt operator++(int) {
    ModInt old(n);
    n += 1;
    return old;
  }
  ModInt operator--(int) {
    ModInt old(n);
    n -= 1;
    return old;
  }
  ModInt operator-() const { return ModInt(mod - n); }
};
template <::std::uint_fast64_t mod>
class Combination {
 private:
  ::std::vector<ModInt<mod>> _fact;
  ::std::vector<ModInt<mod>> _finv;

 public:
  Combination(int range) {
    _fact.resize(range + 1);
    _finv.resize(range + 1);
    _fact[0] = _fact[1] = 1;
    _finv[0] = _finv[1] = 1;
    for (int i = 2; i <= range; i++) {
      _fact[i] = _fact[i - 1] * i;
      _finv[i] = _fact[i].inv();
    }
  }
  ModInt<mod> fact(int x) { return _fact[x]; }
  ModInt<mod> finv(int x) { return _finv[x]; }
  ModInt<mod> comb(int x, int y) { return _fact[x] * _finv[y] * _finv[x - y]; }
  ModInt<mod> homo(int x, int y) { return comb(x + y - 1, y); }
};
const long long MOD = 1e9 + 7;
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n;
  cin >> n;
  long long k = 0, l = 0;
  vector<bool> u(n, true), v(n, false);
  for (int i = 0; i < (int)(n); i++) {
    long long a;
    cin >> a;
    if (a == -1) {
      k++;
      v[i] = true;
    } else {
      u[a - 1] = false;
    }
  }
  for (int i = 0; i < (int)(n); i++)
    if (u[i] && v[i]) l++;
  ModInt<MOD> ans;
  Combination<MOD> Com(k);
  for (int i = 0; i <= l; i++) {
    if (i % 2 == 0) {
      ans += Com.comb(l, i) * Com.fact(k - i);
    } else {
      ans -= Com.comb(l, i) * Com.fact(k - i);
    }
  }
  cout << ans << "\n";
  return 0;
}
