#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 10;
const long long mod = 1e9 + 7;
long long f[N], inv[N];
int pos[N], vis[N];
int a[N];
int n;
long long Pow(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret = ret * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ret;
}
long long C(long long a, long long b) {
  return f[a] * inv[b] % mod * inv[a - b] % mod;
}
void init() {
  f[0] = 1;
  inv[0] = Pow(f[0], mod - 2);
  for (int i = 1; i <= 2000; i++) {
    f[i] = f[i - 1] * i % mod;
    inv[i] = Pow(f[i], mod - 2);
  }
}
int main() {
  init();
  cin >> n;
  int space = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == -1) {
      pos[i] = 1;
      space++;
    } else {
      vis[a[i]] = 1;
    }
    if (a[i] == i) {
      cout << 0 << endl;
      return 0;
    }
  }
  int same = 0;
  for (int i = 1; i <= n; i++) {
    if (pos[i] && !vis[i]) {
      same++;
    }
  }
  long long ans = 0;
  int k = 1;
  for (int i = 0; i <= same; i++) {
    ans += k * C(same, i) * f[space - i] % mod;
    ans = (ans % mod + mod) % mod;
    k = -k;
  }
  cout << ans << endl;
  return 0;
}
