#include <bits/stdc++.h>
using namespace std;
long long int dp[2010][2010];
const long int mod = 1e9 + 7;
int c[2010];
int main() {
  int n, i, j, a, c1 = 0, c2 = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a);
    if (a != -1) {
      c[a]++;
      c[i]++;
    }
  }
  for (i = 1; i <= n; i++) {
    if (c[i] == 1) c2++;
    if (!c[i]) c1++;
  }
  c2 = c2 / 2;
  dp[0][0] = 1;
  for (i = 1; i <= c1 + c2; i++) dp[0][i] = dp[0][i - 1] * i % mod;
  for (i = 0; i <= c1 + c2; i++) dp[1][i] = i * dp[0][i] % mod;
  for (i = 2; i <= c1; i++) {
    for (j = 0; j <= c1 + c2 - i; j++) {
      dp[i][j] = (dp[i - 1][j] * j + dp[i - 2][j + 1] * (i - 1)) % mod;
    }
  }
  printf("%I64d\n", dp[c1][c2]);
  return 0;
}
