#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long long DP[3000][3000];
int T[200000];
bool used[200000];
int main() {
  int N;
  scanf("%d", &N);
  for (int k = 0; k < (N + 1); ++k)
    for (int l = 0; l < (k + 1); ++l) {
      if (k == 0)
        DP[k][l] = 1;
      else if (k == 1 && l == 1)
        DP[k][l] = 0;
      else if (k == l)
        DP[k][l] = ((k - 1) * DP[k - 1][l - 2]) % MOD;
      else
        DP[k][l] = (l * DP[k - 1][l - 1] + (k - l) * DP[k - 1][l]) % MOD;
    }
  int K = N;
  for (int i = 0; i < (N); ++i) {
    scanf("%d", &T[i]);
    if (T[i] > 0) {
      --T[i];
      used[T[i]] = true;
      --K;
    }
  }
  int L = 0;
  for (int i = 0; i < (N); ++i)
    if (T[i] == -1 && !used[i]) ++L;
  printf("%d\n", (int)DP[K][L]);
}
