#include <bits/stdc++.h>
using namespace std;
long long ans;
int n, m, k;
int ar[2003];
int pos[2003];
long long fact[2003];
long long comb[2003][2003];
int main() {
  scanf("%I64d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &ar[i]);
    if (ar[i] != -1) pos[ar[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    if (ar[i] == -1) m++;
    if (ar[i] == -1 && !pos[i]) k++;
  }
  fact[0] = 1;
  for (int i = 1; i <= m; i++) fact[i] = (fact[i - 1] * i) % 1000000007LL;
  for (int i = 0; i <= m; i++) comb[i][0] = 1;
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= i; j++)
      comb[i][j] = (comb[i - 1][j] + comb[i - 1][j - 1]) % 1000000007LL;
  for (int i = 0; i <= k; i++) {
    long long tmp = (comb[k][i] * fact[m - i]) % 1000000007LL;
    if (i % 2)
      ans = (ans - tmp + 1000000007LL) % 1000000007LL;
    else
      ans = (ans + tmp) % 1000000007LL;
  }
  printf("%I64d\n", ans);
  return 0;
}
