#include <bits/stdc++.h>
using namespace std;
long long pow(long long num, long long power) {
  if (power == 0) return 1;
  if (power == 1) return num;
  long long t = pow(num, power / 2);
  return power % 2 ? t * t * num : t * t;
}
int check(int);
int binarysearch(int len) {
  int lo = 1, hi = len, mid, flag;
  while (lo <= hi) {
    mid = hi + lo >> 1;
    (flag = check(mid)) ? lo = mid + 1 : hi = mid - 1;
  }
  return mid - 1 + flag;
}
const int N = 1000 * 100 + 5;
const int MOD = 1000 * 1000 * 1000 + 7;
int debug = 1;
int check(int a) { return a; }
inline int inp() {
  int n = 0, s = 1, c = getchar();
  if (c == '-') s = -1;
  while (c < 48) c = getchar();
  while (c > 47) n = (n << 3) + (n << 1) + c - '0', c = getchar();
  return n * s;
}
int a[N];
int vis1[N], vis2[N];
long long dp[2005][2005], fact[2005];
int solve(int a, int b) {
  if (a == 0) return fact[b];
  if (b < 0) return 0;
  if (a < 0) return 0;
  if (dp[a][b] != -1) return dp[a][b];
  long long &res = dp[a][b];
  res = 0;
  if (b) res = (res + (long long)b * solve(a - 1, b) % MOD) % MOD;
  res = (res + (long long)(a - 1) * solve(a - 2, b + 1) % MOD) % MOD;
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  int i, j, n, t;
  cin >> n;
  for (i = 0; i < n; i++) cin >> a[i + 1];
  for (i = 1; i < n + 1; i++)
    if (a[i] != -1) {
      vis1[a[i]] = 1;
    } else {
      vis2[i] = 1;
    }
  fact[0] = 1;
  for (i = 1; i < 2005; i++) fact[i] = fact[i - 1] * (long long)i % MOD;
  for (i = 0; i < 2005; i++)
    for (j = 0; j < 2005; j++) dp[i][j] = -1;
  int c, d;
  c = d = 0;
  for (i = 1; i < n + 1; i++) {
    if (vis1[i] && vis2[i])
      d++;
    else if (vis2[i])
      c++;
  }
  cout << solve(c, d);
  cin >> i;
}
