#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
using namespace std;
long long jie[2000 + 10], c[2000 + 10][2000 + 10];
long long a[2000 + 10];
bool u[2000 + 10];
int tol, cuo;
void init() {
  c[0][0] = c[1][0] = c[1][1] = 1LL;
  for (int i = 2; i < 2000 + 10; i++) {
    c[i][0] = 1;
    for (int j = 1; j < i; j++) {
      c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % 1000000007;
    }
    c[i][i] = 1LL;
  }
  jie[0] = jie[1] = 1LL;
  for (int i = 2; i < 2000 + 10; i++) jie[i] = (jie[i - 1] * i) % 1000000007;
}
int main() {
  init();
  int n, x;
  while (~scanf("%d", &n)) {
    cuo = tol = 0;
    memset(u, 0, sizeof(u));
    for (int i = 1; i <= n; i++) {
      scanf("%d", &x);
      if (x > -1)
        u[x] = u[i] = 1;
      else
        tol++;
    }
    for (int i = 1; i <= n; i++)
      if (!u[i]) cuo++;
    long long st = 1LL, ans = 0;
    for (int i = 0; i <= cuo; i++) {
      ans = (ans + (st * c[cuo][i] * jie[tol - i]) % 1000000007) % 1000000007;
      st *= -1;
    }
    ans = (ans + 1000000007) % 1000000007;
    cout << ans << '\n';
  }
  return 0;
}
