#include <bits/stdc++.h>
using namespace std;
const int Max = 5e5 + 5;
const int Mod = 1e9 + 7;
int n, a[Max], b[Max];
long long fact[Max];
long long fp(long long x, long long y) {
  long long res = 1;
  for (int i = 0; i <= 60; i++, x = x * x % Mod)
    if (y & 1LL << i) res = res * x % Mod;
  return res;
}
long long C(long long n, long long k) {
  if (k < 0 || k > n || n < 0) return 0;
  return fact[n] * fp(fact[n - k] * fact[k] % Mod, Mod - 2) % Mod;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    if (x == i) return cout << 0 << endl, 0;
    if (x != -1) a[x] = b[i] = 1;
  }
  int cnt = 0, m = 0;
  for (int i = 1; i <= n; i++)
    if (!b[i]) {
      m++;
      if (!a[i]) cnt++;
    }
  long long ans = 0;
  fact[0] = 1;
  for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % Mod;
  for (int i = 1; i <= cnt; i++)
    ans = (ans + C(cnt, i) * fact[m - i] % Mod * (i & 1 ? 1 : Mod - 1) % Mod) %
          Mod;
  cout << (fact[m] - ans + Mod) % Mod << endl;
  return 0;
}
