#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
const long long mod = 1e9 + 7;
long long dp[2010][2010];
long long cao[2010];
long long c[2010][2010];
int a[2010];
bool vis1[2010], vis2[2010];
void pre() {
  int i, j;
  for (i = 0; i <= 2000; i++) {
    c[i][0] = 1LL;
    c[i][i] = 1LL;
  }
  for (i = 2; i <= 2000; i++)
    for (j = 1; j < i; j++) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
}
void work() {
  int i, j;
  dp[0][0] = 1;
  dp[1][1] = 0;
  dp[2][2] = 1;
  cao[0] = 1LL;
  cao[1] = 1LL;
  cao[2] = 2LL;
  for (i = 3; i <= 2000; i++) {
    cao[i] = (cao[i - 1] * i) % mod;
    dp[i][i] = cao[i];
    for (j = 1; j <= i; j++) {
      if (j % 2 == 1)
        dp[i][i] = (dp[i][i] - (c[i][j] * cao[i - j]) % mod + mod) % mod;
      else
        dp[i][i] = (dp[i][i] + (c[i][j] * cao[i - j]) % mod) % mod;
    }
  }
}
void gao(int x, int y) {
  if (dp[x][y] >= 0) return;
  dp[x][y] = 0LL;
  gao(x - 1, y);
  gao(x - 1, y - 1);
  dp[x][y] = (dp[x - 1][y - 1] * y + dp[x - 1][y] * (x - y)) % mod;
  return;
}
int main() {
  int i;
  memset(dp, -1, sizeof(dp));
  pre();
  work();
  int n;
  scanf("%d", &n);
  memset(vis1, 0, sizeof(vis1));
  memset(vis2, 0, sizeof(vis2));
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == -1)
      continue;
    else {
      vis1[i] = 1;
      vis2[a[i]] = 1;
    }
  }
  int x = 0, y = 0;
  for (i = 1; i <= n; i++) {
    if (vis1[i] == 0 && vis2[i] == 0)
      y++;
    else if (vis1[i] == 0 || vis2[i] == 0)
      x++;
  }
  x = x / 2 + y;
  gao(x, y);
  printf("%I64d\n", dp[x][y]);
  return 0;
}
