#include <bits/stdc++.h>
using namespace std;
int n;
int d[2003];
long long fact[2003], C[2003][2003];
long long MOD = 1000000007;
long long add(long long A, long long B) { return (A + B + MOD * 2) % MOD; }
long long mul(long long A, long long B) { return (A * B) % MOD; }
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  int sl = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    if (x != -1) {
      d[x] = d[i] = 1;
    } else {
      sl++;
    }
  }
  int fixed = 0;
  for (int i = 1; i <= n; i++) fixed += (1 - d[i]);
  fact[0] = 1;
  C[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    fact[i] = mul(fact[i - 1], i);
    C[i][0] = 1;
    for (int j = 1; j <= i; j++) C[i][j] = add(C[i - 1][j], C[i - 1][j - 1]);
  }
  long long res = 0;
  for (int i = 0; i <= fixed; i++) {
    long long z = 1;
    if (i % 2 == 1) z = -1;
    res = add(res, z * mul(C[fixed][i], fact[sl - i]));
  }
  cout << res;
  return 0;
}
