#include <bits/stdc++.h>
using namespace std;
int mark[2010] = {0}, posn, num, n = 0, m = 0;
long long d[2010];
int main() {
  scanf("%d", &posn);
  for (int i = 1; i <= posn; i++) {
    scanf("%d", &num);
    if (num != -1) {
      mark[num] = 2;
      if (!mark[i]) mark[i] = 1;
    }
  }
  for (int i = 1; i <= posn; i++) {
    if (mark[i] == 0)
      m++;
    else if (mark[i] == 1)
      n++;
  }
  d[0] = 1;
  for (int i = 1; i <= n; i++) d[0] = (d[0] * i) % 1000000007;
  d[1] = (n * d[0]) % 1000000007;
  for (int i = 2; i <= m; i++)
    d[i] = (n * d[i - 1] + (i - 1) * (d[i - 1] + d[i - 2])) % 1000000007;
  cout << d[m];
  return 0;
}
