#include <bits/stdc++.h>
using namespace std;
void printb(bool b) {
  if (b)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
template <typename T>
T qr() {
  ios::sync_with_stdio(0);
  T rt = 0;
  char c = getchar();
  bool b = false;
  while (c < '0' || c > '9') {
    if (c == '-') b = true;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    rt = (rt << 1) + (rt << 3) + (c ^ 48);
    c = getchar();
  }
  if (b) return -rt;
  return rt;
}
double fp(double a, long long b) {
  ios::sync_with_stdio(0);
  if (b == 0) return 1;
  if (b % 2 == 0)
    return fp(a, b / 2) * fp(a, b / 2);
  else
    return fp(a, b - 1) * a;
}
long long fmp(long long a, long long b, long long p) {
  if (b == 0) return 1;
  long long tmp = fmp(a, b / 2, p);
  if (b % 2 == 0) return (tmp * tmp) % p;
  return (tmp * tmp * a) % p;
}
unsigned long long fmp(unsigned long long a, unsigned long long b,
                       unsigned long long p) {
  unsigned long long tmp = 1;
  a = a % p;
  while (b) {
    if (b & 1) {
      b--;
      tmp = (tmp * a) % p;
    }
    b /= 2;
    a = (a * a) % p;
  }
  return tmp;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long gcdex(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long c = gcdex(b, a % b, y, x);
  y -= a / b * x;
  return c;
}
long long esb[5000007];
bool esa[5000007];
int est;
void EulerSieveInitialize(long long n) {
  int t = 0;
  for (int i = 2; i <= n; i++) {
    if (!esa[i]) esb[t++] = i;
    for (int j = 0; j < t; j++) {
      if (i * esb[j] >= n) break;
      esa[i * esb[j]] = true;
      if (i % esb[j] == 0) break;
    }
  }
  est = t;
}
long long Euler(long long n) {
  long long e = n;
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) e = e - e / i;
    while (n % i == 0) n /= i;
  }
  if (n > 1) e = e - e / n;
  return e;
}
long long cdp[30][30];
void CombinationInitialize(int n) {
  cdp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    cdp[i][0] = 1;
    cdp[i][i] = 1;
    for (int j = 1; j <= n / 2; j++) {
      cdp[i][j] = cdp[i - 1][j - 1] + cdp[i - 1][j];
      cdp[i][i - j] = cdp[i][j];
    }
  }
}
long long wsdp[30];
void WrongSortInitialize(int n, long long p = 0x3f3f3f3f) {
  wsdp[0] = 0;
  wsdp[1] = 0;
  wsdp[2] = 1;
  for (int i = 3; i <= n; i++) wsdp[i] = (i - 1) * (wsdp[i - 1] + wsdp[i - 2]);
}
int a[2007];
long long dp[2007];
const long long md = 1e9 + 7;
int main() {
  ios::sync_with_stdio(0);
  int t, x = 0, y = 0;
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < t; i++) {
    if (a[i] != -1 && a[a[i] - 1] == -1)
      x++;
    else if (a[i] == -1)
      y++;
  }
  y -= x;
  long long tmp = 1;
  for (int i = x; i >= 1; i--) {
    tmp = (tmp * i) % md;
  }
  dp[0] = tmp;
  for (int i = 1; i <= y; i++) {
    dp[i] = ((x + i - 1) * dp[i - 1]) % md;
    if (i > 1) dp[i] += ((i - 1) * dp[i - 2]) % md;
  }
  cout << dp[y] % md;
}
