#include <bits/stdc++.h>
using namespace std;
int a[2020], appear[2020], blank[2020];
long long dp[2020][2020], fact[2020], dr[2020];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == -1) blank[i] = 1;
    appear[a[i]] = 1;
  }
  int m = 0, k = 0;
  for (int i = 1; i <= n; i++) {
    if (blank[i]) {
      m++;
      if (appear[i] == 0) k++;
    }
  }
  fact[0] = fact[1] = 1;
  fact[2] = 2;
  dr[1] = 0;
  dr[2] = 1;
  for (int i = 3; i <= n; i++) {
    fact[i] = fact[i - 1] * i;
    if (fact[i] >= 1000000007) fact[i] %= 1000000007;
    dr[i] = (i - 1) * (dr[i - 1] + dr[i - 2]);
    if (dr[i] >= 1000000007) dr[i] %= 1000000007;
  }
  dp[1][1] = 0;
  dp[1][0] = 1;
  for (int i = 2; i <= m; i++) {
    dp[i][i] = dr[i];
    for (int j = i - 1; j > 0; j--) {
      dp[i][j] = dp[i][j + 1] + dp[i - 1][j];
      if (dp[i][j] >= 1000000007) dp[i][j] %= 1000000007;
    }
    dp[i][0] = fact[i];
  }
  printf("%I64d", dp[m][k]);
  return 0;
}
