#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void checkMin(T &a, T b) {
  if (b < a) a = b;
}
template <typename T>
inline void checkMax(T &a, T b) {
  if (a < b) a = b;
}
const int MOD = 1e9 + 7;
inline void add(int &a, int b) {
  if ((a += b) >= MOD) a -= MOD;
}
int n, a[2048];
bool ind[2048];
int c[2048][2048], f[2048];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    ind[a[i]] = a[i] != -1;
  }
  int o[2] = {};
  for (int i = 1; i <= n; ++i) {
    if (a[i] == -1) {
      ++o[ind[i]];
    }
  }
  for (int i = 0; i < int(2048); ++i) {
    for (int j = 0; j <= i; ++j) {
      add(c[i][j], !j || j == i ? 1 : c[i - 1][j - 1] + c[i - 1][j]);
    }
  }
  int ans = 0;
  for (int i = 0, factorial = 1; i < 2048; ++i) {
    f[i] = factorial = !i ? 1 : (long long)factorial * i % MOD;
    for (int j = 1; j <= i; ++j) {
      add(f[i], MOD - (long long)c[i][j] * f[i - j] % MOD);
    }
    if (o[0] <= i && i <= o[0] + o[1]) {
      add(ans, (long long)c[o[1]][i - o[0]] * f[i] % MOD);
    }
  }
  printf("%d\n", ans);
  return 0;
}
