#include <bits/stdc++.h>
using namespace std;
const int MAX_N = (int)2e5 + 123;
const int mod = (int)1e9 + 7;
int n;
bool used[MAX_N], bad[MAX_N];
int first[MAX_N], _f[MAX_N];
int binpow(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1) res = 1ll * res * a % mod;
    a = 1ll * a * a % mod;
    b >>= 1;
  }
  return res;
}
int C(int n, int k) {
  if (n < k) return 0;
  int res = first[n] * 1ll * _f[k] % mod;
  res = 1ll * res * _f[n - k] % mod;
  return res;
}
void add(int &a, const int &b) {
  a += b;
  if (a >= mod) a -= mod;
}
int main() {
  scanf("%d", &n);
  int cnt = 0;
  for (int i = 1, x; i <= n; i++) {
    scanf("%d", &x);
    if (x == -1)
      used[i] = 1, cnt++;
    else
      bad[x] = 1;
  }
  vector<int> q;
  for (int i = 1; i <= n; i++)
    if (!bad[i] && used[i]) q.push_back(i);
  first[0] = _f[0] = 1;
  for (int i = 1; i <= n; i++) {
    first[i] = 1ll * first[i - 1] * i % mod;
    _f[i] = binpow(first[i], mod - 2);
  }
  int res = 0;
  for (int i = 0; i <= (int)((q).size()); i++) {
    if (i % 2 == 0)
      add(res, 1ll * C((int)((q).size()), i) * first[cnt - i] % mod);
    else
      add(res, mod - 1ll * C((int)((q).size()), i) * first[cnt - i] % mod);
  }
  printf("%d", res);
  return 0;
}
