#include <bits/stdc++.h>
using namespace std;
int n, m, tot;
int a[2222];
bool use[2222];
long long first[2222], c[2222][2222];
int main() {
  for (int i = 0; i <= 2000; ++i) c[i][i] = c[i][0] = 1;
  for (int i = 1; i <= 2000; ++i)
    for (int j = 1; j <= 2000; ++j)
      c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % 1000000007ll;
  first[0] = 1;
  for (int i = 1; i <= 2000; ++i) first[i] = first[i - 1] * i % 1000000007ll;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  for (int i = 1; i <= n; ++i)
    if (a[i] != -1) use[a[i]] = 1;
  for (int i = 1; i <= n; ++i) {
    if (a[i] == -1) {
      tot++;
      if (!use[i]) m++;
    }
  }
  long long ans = first[tot], sub = 0;
  for (int i = 1; i <= m; ++i) {
    long long tmp = c[m][i] * first[tot - i] % 1000000007ll;
    if (i & 1)
      sub = (sub + tmp) % 1000000007ll;
    else
      sub = (sub - tmp + 1000000007ll) % 1000000007ll;
  }
  printf("%I64d", (ans - sub + 1000000007ll) % 1000000007ll);
}
