#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
const int MOD = 1000000007;
int n, a[N], cnt(0), k;
long long mod[N], inver[N];
bool pos[N];
long long extendedGcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1, y = 0;
    return a;
  }
  long long d = extendedGcd(b, a % b, x, y), t = x;
  x = y, y = t - a / b * y;
  return d;
}
long long mulinver(long long a) {
  long long x, y;
  extendedGcd(a, MOD, x, y);
  if (x < 0) x += (-x / MOD + 1) * MOD;
  return x % MOD;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &k);
    if (~k) {
      a[cnt++] = k;
      pos[i] = 1;
    }
  }
  int xa = n - cnt, xb = 0;
  for (int i = 0; i < cnt; ++i) {
    if (!pos[a[i]]) --xa, ++xb;
  }
  mod[0] = 1;
  inver[0] = 1;
  for (int i = 1; i <= xa + xb; ++i) {
    mod[i] = mod[i - 1] * i % MOD;
    inver[i] = mulinver(mod[i]);
  }
  long long ans = 0;
  for (int i = 0, j = 1; i <= xa; ++i, j *= -1) {
    long long add =
        mod[xa + xb - i] * mod[xa] % MOD * inver[xa - i] % MOD * inver[i] % MOD;
    ans += j * add;
  }
  if (ans < 0) ans += (-ans / MOD + 1) * MOD;
  printf("%I64d\n", ans % MOD);
  return 0;
}
