#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
const int MOD = 1000000000 + 7;
int n, a[N];
long long fac[N], C[N][N];
bool used[N];
void init() {
  fac[0] = 1;
  C[0][0] = 1;
  for (int i = 1; i < N; i++) fac[i] = fac[i - 1] * i % MOD;
  for (int i = 1; i < N; i++) {
    C[i][0] = 1;
    for (int j = 1; j <= i; j++) {
      C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;
    }
  }
}
int main() {
  init();
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    if (a[i] != -1) used[a[i]] = 1;
  }
  int cnt = 0, total = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] == -1 && used[i] == 0) {
      cnt++;
    }
    if (a[i] == -1) total++;
  }
  int sign = 1;
  long long ret = 0;
  for (int i = 1; i <= cnt; i++) {
    ret = (ret + sign * C[cnt][i] * fac[total - i]) % MOD;
    sign = -sign;
  }
  ret = ((fac[total] - ret) + MOD) % MOD;
  cout << ret << endl;
  return 0;
}
