#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int N;
int A[2002], where[2002];
int D[2002];
int fact[2002], invfact[2002];
int power(int a, int b) {
  if (b == 0) return 1;
  if (b & 1) return 1LL * a * power(a, b - 1) % MOD;
  return power(1LL * a * a % MOD, b >> 1);
}
int inv(int a) { return power(a, MOD - 2); }
int COMB(int a, int b) {
  int resnow = fact[a];
  resnow = 1LL * resnow * invfact[b] % MOD;
  resnow = 1LL * resnow * invfact[a - b] % MOD;
  return resnow;
}
int main() {
  fact[0] = 1;
  for (int i = 1; i <= 2000; ++i) fact[i] = 1LL * fact[i - 1] * i % MOD;
  invfact[0] = 1;
  for (int i = 1; i <= 2000; ++i)
    invfact[i] = 1LL * invfact[i - 1] * inv(i) % MOD;
  cin >> N;
  for (int i = 1; i <= N; ++i) {
    cin >> A[i];
    if (A[i] != -1) where[A[i]] = i;
  }
  int num1 = 0, num2 = 0;
  for (int i = 1; i <= N; ++i)
    if (where[i] == 0 && A[i] == -1)
      ++num1;
    else if (where[i] == 0)
      ++num2;
  int total = 1LL * fact[num1 + num2] * invfact[num1 + num2 - num1] % MOD;
  for (int i = 1; i <= num1; ++i) {
    int totnow = 1LL * COMB(num1, i) * fact[num1 + num2 - i] % MOD *
                 invfact[num1 + num2 - i - (num1 - i)] % MOD;
    if (i % 2 == 1) {
      total -= totnow;
      if (total < 0) total += MOD;
    } else {
      total += totnow;
      if (total >= MOD) total -= MOD;
    }
  }
  int result = 1LL * total * fact[num2] % MOD;
  cout << result << '\n';
}
