#include <bits/stdc++.h>
const int N = 2010, mod = (int)1e9 + 7;
int n, f[N], a[N], x, y;
long long fa[N], bc[N][N], dp[N], comb[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == i) {
      printf("0");
      return 0;
    }
    if (a[i] != -1) f[a[i]] = true;
  }
  for (int i = 1; i <= n; i++) {
    if (f[i] && a[i] != -1) continue;
    if (!f[i] && a[i] == -1)
      x++;
    else
      y++;
  }
  y /= 2;
  dp[0] = 1;
  for (int i = 1; i <= n; i++) dp[i] = (dp[i - 1] + dp[i - 2]) * (i - 1) % mod;
  fa[0] = 1;
  for (int i = 1; i <= n; i++) fa[i] = fa[i - 1] * i % mod;
  bc[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    bc[i][0] = 1;
    for (int j = 1; j <= i; j++)
      bc[i][j] = (bc[i - 1][j] + bc[i - 1][j - 1]) % mod;
  }
  long long sol = 0;
  comb[0] = 1;
  if (y)
    for (int i = 1; i <= x; i++) comb[i] = fa[i] * bc[i + y - 1][i] % mod;
  for (int i = 0; i <= x; i++) {
    long long a = bc[x][i] * dp[i] % mod * comb[x - i] % mod;
    sol = (sol + a) % mod;
  }
  sol = sol * fa[y] % mod;
  if (sol < 0) sol += mod;
  printf("%lld\n", sol);
  return 0;
}
