#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 * 2 + 5;
const long long mod = 1e9 + 7;
int Map[maxn];
long long dp[maxn];
int n, sumli, sumun;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &Map[i]);
    if (Map[i] == -1) sumli++;
  }
  for (int i = 1; i <= n; i++) {
    if (Map[i] != -1) {
      if (Map[Map[i]] == -1) sumun++;
    }
  }
  sumli -= sumun;
  dp[0] = 1;
  for (long long i = 1; i <= sumun; i++) {
    dp[0] *= i;
    dp[0] %= mod;
  }
  for (int i = 1; i <= sumli; i++) {
    if (i - 1 >= 0) dp[i] += dp[i - 1] * (i - 1);
    if (i - 1 >= 0) dp[i] += sumun * dp[i - 1];
    if (i - 2 >= 0) dp[i] += dp[i - 2] * (i - 1);
    dp[i] %= mod;
  }
  printf("%lld", dp[sumli]);
}
