#include <bits/stdc++.h>
using namespace std;
const int M = 2000 + 5;
long long int mod = 1000000000 + 7;
long long int dp[M][M];
int flag[M];
int a[M];
int main() {
  time_t t_start, t_end;
  t_start = clock();
  int n;
  cin >> n;
  int fre = 0;
  int fix = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] != -1) {
      flag[a[i]] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == -1) {
      if (flag[i] == 0) {
        fix++;
      } else {
        fre++;
      }
    }
  }
  int sz = M - 1;
  dp[0][0] = 1;
  for (int i = 1; i <= sz; i++) {
    dp[i][0] = (dp[i - 1][0] * i) % mod;
  }
  for (int col = 1; col <= sz; col++) {
    for (int row = 0; row + col <= sz; row++) {
      long long int v1 = 0;
      if (col - 1 >= 0) {
        v1 = dp[row][col - 1] * row;
        v1 = v1 % mod;
      }
      long long int v2 = 0;
      if (row + 1 <= sz && col - 2 >= 0) {
        v2 = dp[row + 1][col - 2] * (col - 1);
        v2 = v2 % mod;
      }
      dp[row][col] = (v1 + v2) % mod;
    }
  }
  cout << dp[fre][fix] << endl;
  t_end = clock();
  return 0;
}
