#include <bits/stdc++.h>
using namespace std;
const int MAXn = 2 * 1000 + 17;
const int MOD = 1000000007;
int n;
bool adad[MAXn];
vector<int> ja;
int kol, k;
int c[MAXn][MAXn];
void combin() {
  c[0][0] = 1;
  for (int i = 1; i < MAXn; i++)
    for (int j = 0; j <= i; j++) {
      if (j == 0)
        c[i][j] = c[i - 1][j];
      else if (j == i)
        c[i][j] = c[i - 1][j - 1];
      else
        c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % MOD;
    }
}
long long f(int a) {
  if (a == 0)
    return 1;
  else
    return (f(a - 1) * a) % MOD;
}
void solve(int h, int g) {
  long long sol = 0LL;
  int z = 1;
  for (int i = 0; i <= g; i++) {
    sol += z * f(h - i) * c[g][i];
    if (sol < 0) {
      sol += MOD * ((((-1) * sol) / MOD) + 1);
    }
    sol %= MOD;
    z *= -1;
  }
  cout << sol << endl;
}
int main() {
  combin();
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    if (a == -1)
      ja.push_back(i), kol++;
    else
      adad[a] = 1;
  }
  for (int i = 0; i < ja.size(); i++)
    if (adad[ja[i]] == 0) k++;
  solve(kol, k);
  return 0;
}
