#include <bits/stdc++.h>
using namespace std;
long long i, j, n, x, y;
long long DP[3000][3000];
long long a[3000];
int main() {
  DP[1][0] = 1;
  for (i = 2; i <= 2000; i++) {
    for (j = 0; j < i; j++)
      DP[i][j] = (((i - j) * DP[i - 1][j]) % 1000000007 +
                  (j * DP[i - 1][j - 1]) % 1000000007) %
                 1000000007;
    DP[i][j] = ((i - 1) * DP[i - 1][j - 2]) % 1000000007;
  }
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (j = 1; j <= n; j++)
    if (a[j] == -1) {
      x++;
      y++;
      for (i = 1; i <= n; i++)
        if (a[i] == j) y--;
    }
  cout << DP[x][y] << endl;
}
