#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, x, y;
int t[2002], a[2002];
long long f[22];
int main() {
  int res = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] != -1) t[a[i]]++;
    if (a[i] == -1) y++;
  }
  for (int i = 1; i <= n; i++)
    if (!t[i] && a[i] == -1) x++;
  y = y - x;
  f[0] = 1;
  for (int i = 2; i <= y; i++) f[0] = f[0] * i % mod;
  for (int i = 1; i <= x; i++) {
    f[i] = (i + y - 1) * f[i - 1] % mod;
    if (i > 1) f[i] = (f[i] + (i - 1) * f[i - 2]) % mod;
  }
  printf("%lld", f[x]);
  return 0;
}
