#include <bits/stdc++.h>
using namespace std;
long long dp[150000], a[15000], n, tot, x, MOD = 1e9 + 7;
int main() {
  scanf("%lld", &n);
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    if (a[i] == -1) tot++;
  }
  for (int i = 1; i <= n; i++)
    if (a[i] != -1 && a[a[i]] == -1) x++;
  int y = tot - x;
  dp[0] = 1;
  for (int i = 1; i <= x; i++) {
    dp[0] *= i;
    dp[0] %= MOD;
  }
  for (int i = 1; i <= y; i++) {
    if (i - 1 >= 0) dp[i] += dp[i - 1] * (i - 1);
    if (i - 1 >= 0) dp[i] += x * dp[i - 1];
    if (i - 2 >= 0) dp[i] += dp[i - 2] * (i - 1);
    dp[i] %= MOD;
  }
  printf("%lld\n", dp[y]);
}
