#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, flag = 1;
  char ch = 0;
  while (!isdigit(ch)) {
    ch = getchar();
    if (ch == '-') flag = -1;
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + ch - '0';
    ch = getchar();
  }
  return x * flag;
}
const long long mo = 1e9 + 7;
long long x, y, fac[110000];
long long exgcd(long long a, long long b) {
  if (!b) {
    x = 1;
    y = 0;
    return a;
  }
  long long d = exgcd(b, a % b);
  long long t = x;
  x = y;
  y = t - (a / b) * y;
  return d;
}
long long f(long long o) {
  exgcd(o, mo);
  return (x % mo + mo) % mo;
}
long long c(long long a, long long b) {
  long long up = fac[a];
  long long down = (fac[b] * fac[a - b]) % mo;
  return (up * f(down)) % mo;
}
long long a[110000];
bool vis[110000];
int main() {
  long long n, k = 0, t = 0, i, x, ans = 0;
  n = read();
  for (i = 1, fac[0] = 1; i <= n; i++) {
    fac[i] = (fac[i - 1] * i) % mo;
    a[i] = read();
    if (a[i] != -1) {
      vis[a[i]] = 1;
      if (a[i] == i) {
        printf("0");
        return 0;
      }
    }
  }
  for (i = 1; i <= n; i++) k += (a[i] == -1 && !vis[i]), t += (a[i] == -1);
  for (i = 0; i <= k; i++) {
    x = (c(k, i) * fac[t - i]) % mo;
    if (i & 1)
      ans = ((ans - x) % mo + mo) % mo;
    else
      ans = (ans + x) % mo;
  }
  printf("%lld", ans);
  return 0;
}
