#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int C[2002][2002], jc[2002], a[2002];
bool vis[2002];
void init(int n) {
  C[0][0] = 1;
  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;
  }
  jc[0] = 1;
  for (int i = 1; i <= n; i++) jc[i] = (long long)i * jc[i - 1] % mod;
}
int main() {
  int m = 0, t = 0, n;
  scanf("%d", &n);
  init(n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == -1)
      m++;
    else
      vis[a[i]] = 1;
  }
  for (int i = 1; i <= n; i++)
    if (a[i] < 0 && vis[i] == 0) t++;
  int ans = jc[m];
  for (int i = 1; i <= t; i++) {
    int tmp = (long long)C[t][i] * jc[m - i] % mod;
    if (i & 1)
      ans -= tmp;
    else
      ans += tmp;
    ans %= mod;
  }
  ans = (ans + mod) % mod;
  printf("%d\n", ans);
  return 0;
}
