#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
const int MAX_N = 2000 + 20;
long long D[MAX_N][MAX_N];
int mark[MAX_N];
int node[MAX_N];
int n, Cnt;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i(0); i < int(n); i++) {
    int x;
    cin >> x;
    if (x == -1) {
      ++Cnt;
      node[i] = 1;
    } else
      mark[x - 1] = 1;
  }
  int N = n;
  n = Cnt;
  D[1][1] = 1;
  for (int i(2); i < int(n + 1); i++)
    for (int j(0); j < int(i + 1); j++) {
      if (j == 0) {
        if (i == 2)
          D[i][j] = 1;
        else if (i == 3)
          D[i][j] = 2;
        else
          D[i][j] = ((D[i - 1][j] + D[i - 2][j]) * (i - 1)) % MOD;
      } else {
        D[i][j] = (D[i - 1][j] * (i - j) + D[i - 1][j - 1] * j) % MOD;
      }
    }
  int x = 0;
  for (int i(0); i < int(N); i++)
    if (node[i] && mark[i]) ++x;
  cout << D[n][x] << endl;
  return 0;
}
