#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000000 + 7;
const int maxn = 2000 + 100;
int n;
int a[maxn];
bool mark[maxn];
int tot, common;
int C[maxn][maxn];
int fact[maxn];
int dp[maxn][maxn];
int f(int k) {
  int ret = 0;
  for (int fx = 0; fx <= k; fx++) {
    int sgn = 1 - (fx % 2) * 2;
    ret += sgn * (C[k][fx] * (long long)fact[k - fx] % mod);
    if (ret >= mod) ret -= mod;
    if (ret < 0) ret += mod;
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0, _n = (int)(n); i < _n; i++) cin >> a[i], a[i]--;
  for (int i = 0, _n = (int)(n); i < _n; i++)
    if (a[i] >= 0)
      mark[a[i]] = true;
    else
      tot++;
  for (int i = 0, _n = (int)(n); i < _n; i++)
    if (a[i] < 0 && !mark[i]) common++;
  for (int i = 0, _n = (int)(maxn); i < _n; i++) {
    C[i][0] = C[i][i] = 1;
    for (int j = (int)(1), _n = (int)(i); j < _n; j++) {
      C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
      if (C[i][j] >= mod) C[i][j] -= mod;
    }
  }
  fact[0] = 1;
  for (int i = (int)(1), _n = (int)(maxn); i < _n; i++)
    fact[i] = fact[i - 1] * (long long)i % mod;
  for (int i = 0, _n = (int)(tot + 1); i < _n; i++)
    for (int j = 0, _n = (int)(i + 1); j < _n; j++) {
      if (i == j)
        dp[i][j] = f(i);
      else if (j == 0)
        dp[i][j] = fact[i];
      else
        dp[i][j] = ((long long)(j - 1) * (j >= 2 ? dp[i - 1][j - 2] : 0) +
                    (long long)(i - j) * dp[i - 1][j - 1]) %
                   mod;
    }
  cout << dp[tot][common] << endl;
  {
    int _;
    cin >> _;
    return 0;
  }
}
