#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
const int Mod = 1000000007;
int n;
int a[N], pos[N];
int f[N][N], C[N][N];
int fac[N];
void solve(int x, int y) {
  long long ans = 0;
  for (int i = 0; i <= x; i++) {
    long long cur = C[x][i] * (long long)fac[x + y - i] % Mod;
    if (i & 1)
      ans -= cur;
    else
      ans += cur;
  }
  ans %= Mod;
  ans += Mod;
  ans %= Mod;
  cout << ans << endl;
}
int main() {
  C[0][0] = 1;
  for (int i = 1; i <= 2000; i++)
    for (int j = 0; j <= i; j++)
      C[i][j] = ((j ? C[i - 1][j - 1] : 0) + (j == i ? 0 : C[i - 1][j])) % Mod;
  fac[0] = 1;
  for (int i = 1; i <= 2000; i++) fac[i] = fac[i - 1] * (long long)i % Mod;
  scanf("%d", &n);
  fill(pos, pos + n, -1);
  for (int i = 0; i < (int)(n); i++) {
    scanf("%d", &a[i]);
    if (a[i] != -1) {
      a[i]--;
      pos[a[i]] = i;
    }
  }
  int x = 0, y = 0;
  for (int i = 0; i < (int)(n); i++) {
    if (pos[i] == -1) (a[i] == -1 ? x : y) += 1;
  }
  solve(x, y);
}
