#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
long long fak[2020];
unordered_map<int, long long> buf;
long long f(int g, int r) {
  if (r == 0) return fak[g];
  if (g < 0 || r < 0) return 0;
  if (((buf).find(((((g)*10000) + (r)))) != (buf).end()))
    return buf[(((g)*10000) + (r))];
  long long cnt = 0;
  if (g >= 1) {
    cnt += (g * f(g, r - 1)) % (1000000007);
    cnt %= (1000000007);
  }
  if (r >= 2) {
    cnt += ((r - 1) * f(g + 1, r - 2)) % (1000000007);
    cnt %= (1000000007);
  }
  buf[(((g)*10000) + (r))] = cnt;
  return cnt;
}
int main() {
  fak[0] = 1;
  fak[1] = 1;
  for (int i = (2); i < (2020); i++) fak[i] = (i * fak[i - 1]) % (1000000007);
  int n;
  int a[2000];
  cin >> n;
  int p = 0;
  for (int i = (0); i < (n); i++) {
    cin >> a[i];
    if (a[i] == -1)
      p++;
    else
      a[i]--;
  }
  int g = 0;
  for (int i = (0); i < (n); i++)
    if (a[i] != -1) {
      if (a[a[i]] == -1) g++;
    }
  cout << (f(g, p - g) % (1000000007)) << endl;
  return 0;
}
