#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
const int INF = 2e9;
const long long LNF = 9e18;
const int mod = 1e9 + 7;
const int maxn = 2e3 + 10;
int n, m, k;
bool val[maxn], pos[maxn];
long long C[maxn][maxn], A[maxn];
void init() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    if (x != -1) val[x] = pos[i] = 1;
  }
  k = m = 0;
  for (int i = 1; i <= n; i++) {
    if (!pos[i]) m++;
    if (!pos[i] && !val[i]) k++;
  }
  A[0] = 1;
  C[0][0] = 1;
  for (int i = 1; i <= m; i++) {
    A[i] = (1LL * i * A[i - 1]) % mod;
    C[i][0] = 1;
    for (int j = 1; j <= i; j++)
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
  }
}
void solve() {
  long long ans = A[m];
  for (int i = 1; i <= k; i++) {
    long long tmp = (1LL * C[k][i] * A[m - i]) % mod;
    ans -= (i & 1) ? tmp : -tmp;
    ans = (ans + mod) % mod;
  }
  cout << ans << endl;
}
int main() {
  init();
  solve();
}
