#include <bits/stdc++.h>
using namespace std;
int d[2010][2010] = {};
int a[2010] = {};
int f[2010] = {};
const int md = 1000000007;
int blocked_num[2010];
int blocked_pos[2010];
int main() {
  a[0] = a[1] = 1;
  for (int n = 2; n <= 2000; n++) {
    a[n] =
        (((n * 1ll * a[n - 1]) % md) + (((n - 1) * 1ll * a[n - 2]) % md)) % md;
  }
  for (int i = 1; i < 2000; i++) {
    f[i] = (a[i - 1] * 1ll * (i)) % md;
  }
  d[1][0] = 0;
  d[1][1] = 1;
  for (int i = 2; i <= 2000; i++) {
    d[i][0] = f[i - 1];
    for (int j = 1; j <= i; j++) {
      d[i][j] = (d[i][j - 1] + d[i - 1][j - 1]) % md;
    }
  }
  int p[2010] = {};
  int n;
  scanf("%d", &n);
  int cntall = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", p + i);
    if (p[i] == -1)
      cntall++;
    else {
      blocked_num[p[i]] = true;
      blocked_pos[i] = true;
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (!blocked_num[i] && !blocked_pos[i]) cnt++;
  }
  printf("%d", d[cntall][cntall - cnt]);
  return 0;
}
