#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const int MAXN = 2003;
const int MAXV = 1000010;
inline long long gcd(long long n1, long long n2) {
  return n2 == 0 ? abs(n1) : gcd(n2, n1 % n2);
}
int v[MAXN];
long long PC[MAXN], FAT[MAXN];
const int MOD = 1000000007;
long long power(long long n, long long p) {
  long long base = n, res = 1;
  while (p) {
    if (p & 1) res = (res * base) % MOD;
    base = (base * base) % MOD;
    p >>= 1;
  }
  return res;
}
long long pd[MAXN][MAXN];
long long solve(int x, int y) {
  if (y == 0) return PC[x];
  if (y > x) return 0LL;
  if (pd[x][y] == -1LL) {
    long long W = x - y;
    pd[x][y] = (solve(x - 1, y - 1) * y + solve(x - 1, y) * W) % MOD;
  }
  return pd[x][y];
}
int aux[MAXN];
long long INV[MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  FAT[0] = 1LL;
  for (int i = 1; i < MAXN; ++i) FAT[i] = (FAT[i - 1] * i) % MOD;
  INV[0] = 1LL;
  for (int i = 1; i < MAXN; ++i) INV[i] = power(FAT[i], MOD - 2);
  PC[0] = 1LL;
  for (int i = 1; i < MAXN - 1; ++i) {
    long long sign = 1;
    long long ans = 0LL;
    for (int j = 0; j < i + 1; ++j) {
      ans = (ans + sign * FAT[i] * INV[j]) % MOD;
      sign *= -1;
    }
    ans = (ans + MOD) % MOD;
    PC[i] = ans;
  }
  long long n;
  while (cin >> n) {
    for (int i = 0; i < n; ++i) cin >> v[i];
    memset(aux, 0, sizeof aux);
    for (int i = 0; i < n; ++i)
      if (v[i] != -1) aux[v[i]] = 1;
    int cnt = 0, e = 0;
    for (int i = 0; i < n; ++i)
      if (v[i] == -1) cnt += aux[i + 1], e++;
    memset(pd, -1, sizeof pd);
    cout << solve(e, cnt) << endl;
  }
}
