#include <bits/stdc++.h>
using namespace std;
long long fact[2005];
bool error[2005];
long long tavan(long long a, long long e) {
  if (e == 1) return a % 1000000007;
  long long ans = tavan(a, e / 2);
  ans = (ans * ans) % 1000000007;
  if (e % 2 == 1) ans = ans * a % 1000000007;
  return ans;
}
long long inv(long long a) { return tavan(a, 1000000007 - 2); }
long long C(int n, int k) {
  if (k > n || k < 0) return 0;
  return fact[n] * (inv(fact[k] * fact[n - k] % 1000000007)) % 1000000007;
}
int main() {
  long long n;
  cin >> n;
  fact[0] = 1;
  for (int i = 1; i <= n; i++) {
    fact[i] = fact[i - 1] * i % 1000000007;
    error[i] = true;
  }
  long long d = 0, a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a == -1)
      d++;
    else
      error[a] = error[i + 1] = false;
  }
  long long ans = 0, e = 0;
  for (int i = 1; i <= n; i++)
    if (error[i]) e++;
  for (int i = 0; i <= e; i++) {
    if (i % 2 == 0)
      ans = (ans + C(e, i) * fact[d - i] % 1000000007) % 1000000007;
    else {
      ans = (ans - C(e, i) * fact[d - i] % 1000000007);
      while (ans < 0) ans += 1000000007;
      ans %= 1000000007;
    }
  }
  cout << ans << endl;
  return 0;
}
