#include <bits/stdc++.h>
using namespace std;
const int mo = 1000000007;
int n, x, a[12000], C[2100][2100], fac[2100], num1, num2, ans, i, j;
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) {
    scanf("%d", &x);
    if (x != -1) a[i] = a[x] = 1, num1++;
  }
  for (i = 1; i <= n; ++i)
    if (a[i]) num2++;
  for (i = 0; i <= n; ++i)
    for (j = 0; j <= n; ++j)
      C[i][j] = !j ? 1 : (C[i - 1][j] + C[i - 1][j - 1]) % mo;
  fac[0] = 1;
  for (i = 1; i <= n; ++i) fac[i] = (long long)fac[i - 1] * i % mo;
  for (i = 0; i <= n - num2; ++i) {
    x = (long long)C[n - num2][i] * fac[n - num1 - i] % mo;
    if (i & 1)
      ans = (ans - x) % mo;
    else
      ans = (ans + x) % mo;
  }
  printf("%d\n", (ans + mo) % mo);
}
