#include <bits/stdc++.h>
using namespace std;
long long dp[2005][2005];
int main() {
  ios::sync_with_stdio(false);
  int n;
  while (cin >> n) {
    int a[2005];
    set<int> s;
    for (int i = 1; i <= n; ++i) {
      cin >> a[i];
      if (-1 != a[i]) s.insert(a[i]);
    }
    int cnt1 = 0, cnt2 = 0;
    for (int i = 1; i <= n; ++i) {
      if (-1 == a[i]) {
        ++cnt1;
        if (!s.count(i)) ++cnt2;
      }
    }
    const long long mod = 1000000007;
    long long nn = cnt1, mm = cnt2;
    dp[1][0] = 1;
    dp[1][1] = 0;
    for (long long n = 2; n <= nn; ++n) {
      dp[n][0] = (dp[n - 1][0] * n) % mod;
      dp[n][1] = (dp[n - 1][0] * (n - 1)) % mod;
      for (long long m = 2; m <= mm && m <= n; ++m) {
        dp[n][m] = ((m - 1) * dp[n - 1][m - 2] % mod +
                    (n - m) * dp[n - 1][m - 1] % mod) %
                   mod;
      }
    }
    cout << dp[nn][mm] << endl;
  }
}
