#include <bits/stdc++.h>
using namespace std;
long long dp[2100][2100], mod = 1e9 + 7;
int n, cnt, a[2100], vis[2100], pos[2100], m;
int main() {
  cin >> n;
  cnt = n;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    if (a[i] == -1) continue;
    vis[a[i]] = 1;
    pos[i] = 1;
    cnt--;
  }
  for (int i = 1; i <= n; i++)
    if (!vis[i] && !pos[i]) m++;
  dp[0][0] = 1;
  for (int i = 1; i <= cnt; i++) dp[i][0] = (dp[i - 1][0] * i) % mod;
  for (int i = 1; i <= cnt; i++)
    for (int j = 1; j <= m; j++) {
      dp[i][j] = (dp[i][j - 1] - dp[i - 1][j - 1] + mod) % mod;
    }
  cout << dp[cnt][m];
  return 0;
}
