#include <bits/stdc++.h>
using namespace std;
int a[2010];
long long C[2010][2010];
long long A[2010];
bool use[2010];
int n, m, N;
void init() {
  memset(use, 0, sizeof(use));
  C[0][0] = 1;
  for (int i = 1; i <= 2000; ++i) C[i][0] = 1;
  for (int i = 1; i <= 2000; ++i)
    for (int j = 1; j <= i; ++j)
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % 1000000007;
  A[0] = 1;
  A[1] = 1;
  for (int i = 2; i <= 2000; ++i) A[i] = (A[i - 1] * i) % 1000000007;
  n = 0;
}
void solve() {
  long long Ans = 1;
  Ans = A[n];
  for (int i = 1; i <= N; ++i)
    if (a[i] == -1 && !use[i]) m++;
  long long tmp = 0;
  for (int i = 1; i <= m; ++i) {
    if (i & 1)
      tmp = (tmp + (C[m][i] * A[n - i]) % 1000000007) % 1000000007;
    else
      tmp = (1000000007 + tmp - (C[m][i] * A[n - i]) % 1000000007) % 1000000007;
  }
  cout << (Ans + 1000000007 - tmp) % 1000000007;
}
int main() {
  scanf("%d", &N);
  init();
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &a[i]);
    if (a[i] != -1)
      use[a[i]] = 1;
    else
      n++;
  }
  solve();
  return 0;
}
