#include <bits/stdc++.h>
using namespace std;
int a[2010], use[2010], n;
long long C[2010][2010], fact[2010];
void read() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    if (a[i] != -1) use[a[i]] = 1;
  }
  C[0][0] = 1, fact[0] = 1;
  for (int i = 1; i <= n; ++i) {
    C[i][0] = 1;
    for (int j = 1; j <= i; ++j)
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % 1000000007;
    fact[i] = fact[i - 1] * i % 1000000007;
  }
}
void work() {
  static int x[2010], y[2010];
  int s1 = 0, s2 = 0, s3 = 0;
  for (int i = 1; i <= n; ++i) {
    if (a[i] == -1) x[++s1] = i;
    if (use[i] == 0) y[++s2] = i;
    if (a[i] == -1 && use[i] == 0) ++s3;
  }
  long long ans = fact[s1];
  for (int i = 1, type = -1; i <= s3; ++i) {
    ans = (ans + C[s3][i] * fact[s1 - i] % 1000000007 * type + 1000000007) %
          1000000007;
    type *= -1;
  }
  cout << ans << endl;
}
int main() {
  read();
  work();
  return 0;
}
