#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long maxN = 2001;
long long dp[maxN];
long long rec(long long a, long long b) {
  if (dp[a] != -1) return dp[a];
  long long ans = 0;
  ans = (ans + (b * rec(a - 1, b))) % mod;
  ans = (ans + ((a - 1) * rec(a - 1, b))) % mod;
  ans = (ans + ((a - 1) * rec(a - 2, b))) % mod;
  dp[a] = ans;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  memset(dp, -1, sizeof(dp));
  long long n;
  cin >> n;
  vector<long long> a(n);
  long long t1 = 0, t2 = 0;
  vector<long long> vis(n + 1, 0);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] != -1) vis[a[i]]++;
  }
  for (long long i = 0; i < n; i++) {
    if (a[i] == -1) {
      if (vis[i + 1] == 0)
        t1++;
      else
        t2++;
    }
  }
  dp[0] = 1;
  dp[1] = t2;
  long long ans = rec(t1, t2);
  for (long long i = 1; i <= t2; i++) {
    ans = (ans * i) % mod;
  }
  cout << ans << '\n';
  return 0;
}
