#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:65777216")
using namespace std;
const long double EPS = 1e-11;
const int INF = 2000000000;
const long long lINF = 9223372036854775800;
const long double PI = 3.14159265358979323846;
const int MAXN = 10000;
const int BASE = 131072;
const long long MOD = 1000000007;
long long dp[2005][2005];
int main() {
  int n, i, j, x, m = 0, k = 0, u1[2005], u2[2005];
  long long fc[2005], ans;
  cin >> n;
  for (i = 0; i < n; i++) {
    u1[i] = 0;
    u2[i] = 0;
  }
  for (i = 0; i < n; i++) {
    cin >> x;
    if (x == -1) {
      m++;
      u1[i] = 1;
    } else {
      x--;
      u2[x] = 1;
    }
  }
  for (i = 0; i < n; i++)
    if (!u2[i] && u1[i]) k++;
  fc[0] = 0;
  fc[1] = 1;
  for (i = 2; i <= m; i++) fc[i] = (fc[i - 1] * i) % MOD;
  for (i = 1; i <= m; i++) dp[i][0] = 0;
  for (i = 1; i <= m; i++)
    for (j = 1; j <= k; j++) {
      dp[i][j] = (fc[i - 1] + dp[i - 1][j - 1] * (i - j)) % MOD;
      if (j > 1) dp[i][j] = (dp[i][j] + dp[i - 1][j - 2] * (j - 1)) % MOD;
    }
  ans = fc[m] - dp[m][k];
  ans = (ans + MOD) % MOD;
  cout << ans;
  return 0;
}
