#include <bits/stdc++.h>
using namespace std;
template <typename T, typename TT>
ostream &operator<<(ostream &s, pair<T, TT> t) {
  return s << "(" << t.first << "," << t.second << ")";
}
template <typename T>
ostream &operator<<(ostream &s, vector<T> t) {
  s << "{";
  for (int i = 0; i < t.size(); i++)
    s << t[i] << (i == t.size() - 1 ? "" : ",");
  return s << "}" << endl;
}
inline void pisz(int x) { printf("%d\n", x); }
long long dp[3111][3111];
long long go(int K, int N) {
  if (dp[K][N] != -1) return dp[K][N];
  if (K == 0) {
    if (N == 0) return 1;
    return dp[0][N] = (N * go(0, N - 1)) % 1000000007;
  }
  if (K == 1) {
    if (N == 0) return 0;
    return dp[1][N] = (N * go(0, N)) % 1000000007;
  }
  return dp[K][N] =
             (N * go(K - 1, N) + (K - 1) * go(K - 2, N + 1)) % 1000000007;
}
bool used[3111];
int fast(vector<int> v) {
  int n = v.size();
  for (int i = 1; i <= n; i++) used[i] = 0;
  for (int i = 0; i < n; i++)
    if (v[i] != -1) used[v[i]] = 1;
  int K = 0, N = 0;
  for (int i = 1; i <= n; i++)
    if (!used[i]) {
      if (v[i - 1] == -1)
        K++;
      else
        N++;
    }
  return go(K, N);
}
int main() {
  ios_base::sync_with_stdio(0);
  for (int i = 0; i < 2111; i++)
    for (int j = 0; j < 2111; j++) dp[i][j] = -1;
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  cout << fast(v);
  return 0;
}
