#include <bits/stdc++.h>
using namespace std;
const long long int N = 2005;
bool mark[N], position[N];
int main() {
  long long int n;
  cin >> n;
  long long int dp[n + 1][n + 1];
  dp[0][0] = 1;
  dp[1][0] = 0;
  dp[0][1] = 1;
  for (long long int i = 2; i <= n; i++) {
    dp[i][0] = ((i - 1) * (dp[i - 1][0] + dp[i - 2][0])) % 1000000007;
    dp[0][i] = (dp[0][i - 1] * i) % 1000000007;
  }
  for (long long int i = 1; i <= n; i++) {
    long long int x;
    cin >> x;
    if (x == -1)
      position[i] = 1;
    else
      mark[x] = 1;
  }
  long long int k = 0, l = 0;
  for (long long int i = 1; i <= n; i++) {
    if (!mark[i]) k++;
    if (!mark[i] && position[i]) l++;
  }
  for (long long int i = 1; i <= l; i++) {
    for (long long int j = 1; j <= k - l; j++) {
      dp[i][j] = ((i * dp[i - 1][j]) + (j * dp[i][j - 1])) % 1000000007;
    }
  }
  long long int ans = dp[l][k - l];
  cout << ans;
}
