#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long dp[2010][2010], fact[2010];
int n, chk[2010], m, cnt;
int main() {
  for (int i = 0; i <= 2000; i++) {
    dp[i][0] = 1;
    for (int j = 1; j <= i; j++) {
      dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % mod;
    }
  }
  scanf("%d", &n);
  int a;
  fact[0] = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a);
    if (a != -1) {
      chk[i] = 1;
      chk[a] = 1;
      m++;
    }
    fact[i] = (i * fact[i - 1]) % mod;
  }
  for (int i = 1; i <= n; i++) cnt += chk[i];
  cnt = n - cnt;
  m = n - m;
  long long ans = 0;
  for (int i = 0; i <= cnt; i++) {
    if (i % 2)
      ans = (ans - (fact[m - i] * dp[cnt][i]) % mod + mod) % mod;
    else
      ans = (ans + (fact[m - i] * dp[cnt][i]) % mod) % mod;
  }
  printf("%lld", ans);
  return 0;
}
