#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
const int mod = 1000000007;
int a[N];
bool vis[N];
long long dp[N][N];
int main() {
  memset(vis, 0, sizeof(vis));
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] != -1) vis[a[i]] = true;
  }
  int s = 0, t = 0;
  for (int i = 1; i <= n; i++)
    if (!vis[i]) {
      s++;
      if (a[i] == -1) t++;
    }
  dp[0][0] = 1;
  for (int i = 1; i <= s; i++) dp[i][0] = dp[i - 1][0] * i % mod;
  dp[1][1] = 0;
  long long fact = 1;
  for (int i = 2; i <= s; i++) {
    dp[i][1] = fact * (i - 1) % mod;
    fact = fact * i % mod;
  }
  for (int j = 2; j <= t; j++)
    for (int i = j; i <= s; i++) {
      dp[i][j] = dp[i - 1][j - 2] * (j - 1) + dp[i - 1][j - 1] * (i - j);
      dp[i][j] %= mod;
    }
  cout << dp[s][t] << endl;
  return 0;
}
