#include <bits/stdc++.h>
using namespace std;
int n;
int p[2001][2001];
int a[2001];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int t = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == -1) {
      t++;
    }
  }
  int t1 = t;
  for (int i = 0; i < n; i++) {
    if (a[i] != -1) {
      if (a[a[i] - 1] == -1) {
        t1--;
      }
    }
  }
  p[0][0] = 1;
  int n1 = 1;
  int n2 = 1;
  for (int i = 1; i <= n; i++) {
    n1 = (1LL * n1 * i) % 1000000007;
    p[i][0] = n1;
    p[i][1] = (n1 - n2 + 1000000007) % 1000000007;
    for (int j = 2; j <= i; j++) {
      p[i][j] =
          ((1LL * (i - 1) * p[i - 1][j - 1]) % 1000000007 +
           (1LL * (j - 1) * (i >= 2 ? p[i - 2][j - 2] : 0)) % 1000000007) %
          1000000007;
    }
    n2 = (1LL * n2 * i) % 1000000007;
  }
  cout << p[t][t1] << endl;
  return 0;
}
