#include <bits/stdc++.h>
using namespace std;
long long c[2005][2005], fac[2005];
void init() {
  c[0][0] = 1;
  for (int i = 1; i <= 2000; ++i) {
    c[i][0] = 1;
    for (int j = 1; j <= 2000; ++j)
      c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % 1000000007;
  }
}
bool use[2005];
long long dp[2005];
int main() {
  init();
  fac[0] = 1;
  for (int i = 1; i <= 2000; ++i) fac[i] = fac[i - 1] * i % 1000000007;
  int n, x, k = 0, p = 0;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> x;
    if (x == -1)
      ++p;
    else
      use[i] = use[x] = true;
  }
  for (int i = 1; i <= n; ++i)
    if (!use[i]) ++k;
  for (int i = 0; i <= k; ++i) dp[i] = c[k][i] * fac[p - i] % 1000000007;
  for (int i = k - 1; i >= 0; --i)
    for (int j = i + 1; j <= k; ++j)
      dp[i] =
          ((dp[i] - dp[j] * c[j][i] % 1000000007) % 1000000007 + 1000000007) %
          1000000007;
  cout << dp[0] << endl;
  return 0;
}
