#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:267386880")
using namespace std;
int cnk[2005][2005];
int fact[2005];
void prec() {
  cnk[0][0] = 1;
  for (int i(1); i <= (2004); ++i)
    for (int j(0); j <= (i); ++j)
      cnk[i][j] =
          ((j == 0 ? 0 : cnk[i - 1][j - 1]) + (j == i ? 0 : cnk[i - 1][j])) %
          1000000007;
  fact[0] = 1;
  for (int i(1); i <= (2004); ++i)
    fact[i] = (i * 1ll * fact[i - 1]) % 1000000007;
}
int main() {
  prec();
  int n;
  scanf("%d", &n);
  vector<int> d(n);
  set<int> SET;
  for (int i(0); i <= ((long long)(n)-1); ++i) {
    scanf("%d", &d[i]);
    if (d[i] != -1) SET.insert(d[i]);
  }
  int hm(0);
  for (int i(0); i <= ((long long)(n)-1); ++i) {
    if (d[i] == -1 && !SET.count(i + 1)) ++hm;
  }
  long long ans(0);
  int quest(n - ((int)SET.size()));
  for (int i(0); i <= ((long long)(hm + 1) - 1); ++i) {
    long long add((cnk[hm][i] * 1ll * fact[quest - i]) % 1000000007);
    if (i & 1)
      ans -= add;
    else
      ans += add;
    ans = (ans + 1000000007) % 1000000007;
  }
  printf("%d\n", (int)ans);
  return 0;
}
