#include <bits/stdc++.h>
long long max(long long x, long long y) { return x > y ? x : y; }
long long min(long long x, long long y) { return x < y ? x : y; }
using namespace std;
const long long N = 2014;
const long long MOD = 1000000007;
long long a[N], o[N];
long long n;
long long dp[N][N];
long long rec(long long g, long long b) {
  if (dp[g][b]) return dp[g][b];
  if (b < 0) return 1;
  if (b == 0) {
    long long res = 1;
    for (long long i = 0; i < g; i++) res = (res * (i + 1)) % MOD;
    return dp[g][b] = res;
  }
  return dp[g][b] = (((b - 1) * rec(g + 1, b - 2)) % MOD +
                     (g > 0) * (g * rec(g, b - 1)) % MOD) %
                    MOD;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    o[a[i]] = 1;
  }
  long long good = 0, bad = 0;
  for (long long i = 0; i < n; i++)
    if (a[i] == -1 && o[i + 1])
      good++;
    else if (a[i] == -1)
      bad++;
  cout << rec(good, bad);
  return 0;
}
