#include <bits/stdc++.h>
using namespace std;
int n;
int cnt = 0;
int a[200001];
bool f[200001];
long long g[200001];
long long ig[200001];
const long long Mod = 1e9 + 7;
int sum;
long long power(long long x, int n) {
  if (n == 0) return 1;
  if (n % 2 == 0)
    return power(x * x % Mod, n / 2);
  else
    return x * power(x * x % Mod, n / 2) % Mod;
}
long long nck(int n, int k) { return g[n] * ig[k] % Mod * ig[n - k] % Mod; }
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] != -1) f[a[i]] = true;
    sum += a[i] == -1;
  }
  for (int i = 1; i <= n; i++) {
    if (!f[i] && a[i] == -1) cnt++;
  }
  g[0] = 1;
  for (int i = 1; i <= n; i++) {
    g[i] = g[i - 1] * i % Mod;
  }
  ig[n] = power(g[n], Mod - 2);
  for (int i = n - 1; i >= 0; i--) {
    ig[i] = ig[i + 1] * (i + 1) % Mod;
  }
  long long ans = g[sum];
  int tt = -1;
  for (int i = 1; i <= cnt; i++) {
    long long x = tt * nck(cnt, i) * g[sum - i];
    x = (x + Mod * Mod) % Mod;
    (ans += x) %= Mod;
    tt *= -1;
  }
  cout << ans;
  return 0;
}
