#include <bits/stdc++.h>
using namespace std;
long long gcd(long long m, long long n) {
  long long r;
  while (n != 0) {
    r = m % n;
    m = n;
    n = r;
  }
  return m;
}
long long expmod(long long a, long long b) {
  long long x = 1, y = a;
  while (b > 0) {
    if (b & 1) x = (x * y) % 1000000007;
    y = (y * y) % 1000000007;
    b >>= 1;
  }
  return (x) % 1000000007;
}
long long inv(long long n) { return expmod(n, 1000000007 - 2); }
long long dp[2010][2010];
int main() {
  long long n;
  cin >> n;
  long long cnt = 0;
  long long a[n + 1];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == -1) cnt++;
  }
  long long temp = cnt;
  for (long long i = 0; i < n; i++)
    if (a[i] != -1)
      if (a[a[i] - 1] == -1) temp--;
  dp[0][0] = 1;
  for (long long i = 1; i <= n; i++) dp[i][0] = (dp[i - 1][0] * i) % 1000000007;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= i; j++) {
      dp[i][j] = (dp[i][j - 1] - dp[i - 1][j - 1]) % 1000000007;
      dp[i][j] = (dp[i][j] + 1000000007) % 1000000007;
    }
  }
  cout << dp[cnt][temp] << endl;
  return 0;
}
