#include <bits/stdc++.h>
const int maxn = 2010;
const int Mod = 1e9 + 7;
using namespace std;
int main() {
  int n;
  cin >> n;
  long long a[maxn], vis[maxn], dp[maxn], jie[maxn];
  memset(vis, 0, sizeof(vis));
  int tx = 0, ty = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] != -1) vis[a[i]] = 1;
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == -1) {
      if (vis[i])
        tx++;
      else
        ty++;
    }
  }
  dp[0] = 1;
  dp[1] = tx % Mod;
  for (int i = 2; i <= ty; i++) {
    dp[i] = (tx * dp[i - 1] % Mod + (i - 1) * dp[i - 1] % Mod +
             dp[i - 2] * (i - 1) % Mod) %
            Mod;
  }
  jie[0] = 1;
  for (int i = 1; i <= n; i++) {
    jie[i] = jie[i - 1] * i % Mod;
  }
  cout << dp[ty] * jie[tx] % Mod << endl;
  return 0;
}
