#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 9, mod = 1e9 + 7;
int arr[N];
bool occured[N];
long long dp[N][N];
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    if (arr[i] > 0) {
      occured[arr[i]]++;
    }
  }
  int num = 0;
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    if (arr[i] > 0) {
      for (int j = 0; j <= n; j++) dp[i][j] = dp[i - 1][j];
      continue;
    }
    if (occured[i]) {
      for (int j = 0; j <= n; j++) dp[i][j] = dp[i - 1][j];
      for (int j = 0; j <= n; j++) {
        if (j) {
          dp[i][j - 1] += dp[i][j] * j % mod;
          dp[i][j - 1] %= mod;
        }
        if (num - j > 0) dp[i][j] = (dp[i][j] + dp[i][j] * (num - j)) % mod;
      }
    } else {
      for (int j = 1; j <= n; j++) dp[i][j] = dp[i - 1][j - 1];
      for (int j = 1; j <= n; j++) {
        if (j >= 2) {
          dp[i][j - 2] += dp[i][j] * (j - 1) % mod;
          dp[i][j - 2] %= mod;
        }
        if (num - j + 1 > 0) {
          dp[i][j - 1] += dp[i][j] * (num - j + 1) % mod;
          dp[i][j - 1] %= mod;
        }
      }
    }
    num++;
  }
  cout << dp[n][0] << '\n';
  return 0;
}
