#include <bits/stdc++.h>
using namespace std;
const long long MOD = (1e9) + 7, maxN = 2000 + 40;
long long cmp[maxN][maxN], fac[maxN];
int n, tmp, cur;
int dp[maxN] = {0};
int bp[maxN] = {0};
long long ans;
int main() {
  scanf("%d", &n);
  for (int(i) = (0); (i) < int(n); ++(i)) {
    scanf("%d", &tmp);
    if (tmp == -1)
      cur++;
    else {
      dp[i + 1] = 1;
      bp[tmp] = 1;
    }
  }
  fac[0] = 1;
  for (int(i) = (1); (i) < int(cur + 1); ++(i)) fac[i] = (i * fac[i - 1]) % MOD;
  for (int(i) = (1); (i) < int(cur + 1); ++(i))
    for (int(j) = (1); (j) < int(i + 1); ++(j))
      if (j == 1)
        cmp[i][j] = i;
      else if (j == i)
        cmp[i][j] = 1;
      else
        cmp[i][j] = (cmp[i - 1][j] + cmp[i - 1][j - 1]) % MOD;
  ans += fac[cur];
  int ted = 0;
  for (int(i) = (1); (i) < int(n + 1); ++(i)) {
    if (dp[i] != 1 and bp[i] != 1) {
      ted++;
      ans = (ans - fac[cur - 1] + MOD) % MOD;
      for (int(j) = (1); (j) < int(ted); ++(j)) {
        if (j % 2) {
          ans = (ans + ((fac[cur - j - 1] * cmp[ted - 1][j]) % MOD)) % MOD;
        } else
          ans = (((ans + MOD) - ((fac[cur - j - 1] * cmp[ted - 1][j]) % MOD))) %
                MOD;
      }
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
