#include <bits/stdc++.h>
using namespace std;
int main() {
  static int C[2005][2005];
  C[0][0] = 1;
  int i, j;
  for (i = 1; i < 2005; i++) {
    C[i][0] = 1;
    for (j = 1; j < i; j++) {
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % 1000000007;
    }
    C[i][i] = 1;
  }
  static int fact[2005];
  fact[0] = 1;
  for (i = 1; i < 2005; i++) {
    fact[i] = (int)(((long long)(fact[i - 1]) * (long long)(i)) % 1000000007LL);
  }
  int N;
  scanf("%d", &N);
  static int data[2005];
  static int num[2005];
  for (i = 0; i < N; i++) num[i] = -1;
  int fr = 0;
  for (i = 0; i < N; i++) {
    scanf("%d", &(data[i]));
    if (data[i] == -1)
      fr++;
    else {
      (data[i])--;
      num[data[i]] = i;
      if (data[i] == i) {
        printf("0\n");
        return 0;
      }
    }
  }
  int K = 0;
  for (i = 0; i < N; i++) {
    if ((num[i] == -1) && (data[i] == -1)) {
      K++;
    }
  }
  int res = 0;
  int sign = 1;
  for (i = 0; i <= K; i++) {
    int val =
        (int)(((long long)(C[K][i]) * (long long)(fact[fr])) % 1000000007LL);
    if (sign == 1) {
      res = (res + (val)) % 1000000007;
    } else {
      res = (res - (val) + 1000000007) % 1000000007;
    }
    fr--;
    sign *= -1;
  }
  printf("%d\n", res);
  return 0;
}
