#include <bits/stdc++.h>
using namespace std;
int n, i, uu, sum, ans, j, tmp, a[2100], C[2100][2100], fac[2100];
bool used1[2100], used2[2100];
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] > 0) used1[i] = used2[a[i]] = true, uu++;
    if (a[i] == i) {
      printf("0\n");
      return 0;
    }
  }
  for (i = 1; i <= n; i++)
    if (!used1[i] && !used2[i]) sum++;
  for (C[0][0] = 1, i = 1; i <= n; i++)
    for (C[i][0] = 1, j = 1; j <= i; j++)
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % 1000000007;
  for (fac[0] = 1, i = 1; i <= n; i++)
    fac[i] = 1LL * fac[i - 1] * i % 1000000007;
  for (i = 0; i <= sum; i++) {
    tmp = 1LL * C[sum][i] * fac[n - i - uu] % 1000000007;
    if (i & 1)
      ans = (ans - tmp) % 1000000007;
    else
      ans = (ans + tmp) % 1000000007;
  }
  printf("%d\n", (ans + 1000000007) % 1000000007);
}
