#include <bits/stdc++.h>
using namespace std;
void BinarySay(long long x, long long y = 60) {
  for (long long i = 0; i < (y); i++) cout << (x >> (y - 1 - i) & 1);
  cout << endl;
}
const long long INFL = 1LL << 60;
long long MOD = 1000000007;
struct mint {
  long long x;
  mint(long long x) : x(x % MOD) {}
  mint& operator+=(const mint a) {
    (x += a.x) %= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    (x += MOD - a.x) %= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint& operator%=(const mint a) {
    (x %= a.x);
    return *this;
  }
  mint& operator++(int) {
    (x += 1) %= MOD;
    return *this;
  }
  mint& operator--(int) {
    (x += MOD - 1) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint operator%(const mint a) const {
    mint res(*this);
    return res %= a;
  }
  mint po(long long t) const {
    if (!t) return 1;
    mint a = po(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inverse() const { return po(MOD - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inverse(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
  bool operator==(const mint a) { return this->x == a.x; }
  bool operator!=(const mint a) { return this->x != a.x; }
  void get() { cout << x << endl; }
  void ge() { cout << x << " "; }
};
const mint Mint = 0;
mint pow_mod(long long x, long long k) {
  mint res = 1;
  mint a = x;
  while (k > 0) {
    if (k % 2) {
      res *= a;
    }
    a *= a;
    k /= 2;
  }
  return res;
}
const int MAXcomb = 200010;
long long fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAXcomb; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
mint comb(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  mint res = fac[n];
  res *= finv[k] * finv[n - k];
  return res;
}
mint comb_simple(long long N, long long K) {
  mint res = 1;
  for (long long i = 0; i < (K); i++) res *= (N - i);
  mint k = 1;
  for (long long i = 0; i < (K); i++) k *= (i + 1);
  res /= k;
  return res;
}
const long long MAXStir2 = 3010;
vector<vector<mint>> Stir2memo(MAXStir2, vector<mint>(MAXStir2, Mint));
vector<mint> Bellmemo(MAXStir2, Mint);
void Stir2init() {
  Stir2memo[0][0] = 1;
  for (long long i = 0; i < (MAXStir2 - 1); i++)
    for (long long j = 0; j < (i + 1); j++)
      Stir2memo[i + 1][j + 1] = Stir2memo[i][j] + Stir2memo[i][j + 1] * (j + 1);
  for (long long i = 0; i < (MAXStir2); i++) {
    Bellmemo[i] = 0;
    for (long long j = 0; j < (i + 1); j++) Bellmemo[i] += Stir2memo[i][j];
  }
}
mint Stir2(long long i, long long j) {
  if (i < 0 || j < 0 || i < j) return 0;
  return Stir2memo[i][j];
}
mint Bell(long long x) {
  if (x < 0) return 0;
  return Bellmemo[x];
}
mint kai_mod(long long K) {
  if (K < 0) return 0;
  if (K == 0) return 1;
  return kai_mod(K - 1) * K;
}
long long N;
vector<long long> A;
void solve() {
  vector<bool> exist(N, 0);
  vector<long long> pos;
  vector<long long> erased;
  for (long long i = 0; i < (N); i++) {
    if (A[i] == -2) {
      pos.push_back(i);
    } else {
      exist[A[i]] = 1;
    }
  }
  for (long long i = 0; i < (N); i++)
    if (exist[i] == 0) erased.push_back(i);
  sort(pos.begin(), pos.end());
  sort(erased.begin(), erased.end());
  long long n = pos.size();
  long long comm = 0, dif = 0;
  long long t = 0;
  for (long long second = 0; second < n; second++) {
    while (pos[second] > erased[t] && t + 1 < n) {
      t++;
    }
    if (pos[second] == erased[t]) {
      comm++;
      t++;
      continue;
    }
  }
  dif = n - comm;
  mint ans = 0;
  for (long long i = 0; i <= comm; i++) {
    mint add = 0;
    add = comb(comm, i) * kai_mod(n - i);
    if (i & 1)
      ans -= add;
    else
      ans += add;
  }
  ans.get();
}
int main() {
  COMinit();
  cin >> N;
  A.resize(N);
  for (long long i = 0; i < (N); i++) {
    cin >> A[i];
    A[i]--;
  }
  solve();
}
