#include <bits/stdc++.h>
using namespace std;
const double pi = 3.14159265358979323846264338327950288419716939937511;
const double eps = 1e-9;
char ch_ch_ch[1 << 20];
inline string gs() {
  scanf("%s", ch_ch_ch);
  return string(ch_ch_ch);
}
inline string gl() {
  gets(ch_ch_ch);
  return string(ch_ch_ch);
}
inline int gi() {
  int x;
  scanf("%d", &x);
  return x;
}
const int inf = 1000000000;
template <typename T>
class FenwickSummator {
 private:
  T *fenv;
  int n;

 public:
  FenwickSummator(int N) {
    n = N;
    fenv = new T[N + 1];
    memset(fenv, 0, (N + 1) * sizeof(T));
  }
  void add(int p, T val) {
    if (p < 0 || p >= n) return;
    for (++p; p <= n; p += p & -p) fenv[p] = max(fenv[p], val);
  }
  T maxi(int p) {
    if (p < 0) return 0;
    if (p >= n) p = n - 1;
    T res = 0;
    for (++p; p > 0; p -= p & -p) res = max(res, fenv[p]);
    return res;
  }
  ~FenwickSummator() { delete[] fenv; }
};
int n;
int a[100100];
int was[100100];
int K, D;
int dp[2010][2010];
int fc[2010];
const int mod = 1000000007;
int R(int k, int d) {
  int &r = dp[k][d];
  if (r != -1) return r;
  if (k == 0 && d == 0) return r = 1;
  long long res = 0;
  if (k >= 2) res = res + (k - 1) * 1ll * (R(k - 2, d) + R(k - 1, d));
  if (k >= 1 && d > 0) res = res + d * 1ll * R(k - 1, d);
  if (k == 0) res = fc[d];
  return r = res % mod;
}
void solution() {
  n = gi();
  for (int i = 0; i < (n); ++i) a[i] = gi();
  for (int i = 0; i < (n); ++i)
    if (a[i] != -1) was[a[i] - 1] = 1;
  K = 0, D = 0;
  for (int i = 0; i < (n); ++i)
    if (a[i] == -1) {
      if (was[i])
        D++;
      else
        K++;
    }
  memset(dp, -1, sizeof(dp));
  fc[0] = 1;
  for (int i = (1); i < (2010); ++i) fc[i] = (i * 1ll * fc[i - 1]) % mod;
  cout << R(K, D) << endl;
}
int main(int argc, char **argv) {
  solution();
  return 0;
}
