#include <bits/stdc++.h>
using namespace std;
const int p = (int)1e9 + 7;
int a[2001];
long long fact[2001], dp[2001], r[2001][2001];
int n, max_id;
bool e[2001], f[2001];
void solve() {
  fact[0] = fact[1] = 1;
  dp[1] = 0;
  for (int i = 2; i < 2001; i++) {
    if (i % 2 == 0)
      dp[i] = (((long long)i) * dp[i - 1] + 1) % p;
    else
      dp[i] = (((long long)i) * dp[i - 1] - 1) % p;
    fact[i] = (((long long)i) * fact[i - 1]) % p;
  }
  return;
}
int main() {
  int x = 0, y = 0;
  long long ans = 0;
  solve();
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == -1)
      e[i] = true;
    else
      f[a[i]] = true;
  }
  for (int i = 1; i <= n; i++) {
    if (e[i]) {
      if (f[i])
        y++;
      else
        x++;
    }
  }
  for (int i = 1; i < 2001; i++) {
    r[0][i] = fact[i];
    r[1][i] = (((long long)i) * fact[i]) % p;
    r[i][0] = dp[i];
  }
  for (int i = 2; i <= x; i++) {
    for (int j = 1; j <= y; j++) {
      r[i][j] =
          (((long long)i) * r[i - 1][j] + ((long long)j) * r[i][j - 1]) % p;
    }
  }
  printf("%d", r[x][y]);
  return 0;
}
