#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2007, M = 1000000007;
int n, a, fix, neu;
long long dp[MAX_N][MAX_N];
bool num[MAX_N], place[MAX_N];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    if (a != -1) {
      num[a] = true;
      place[i] = true;
    }
  }
  for (int i = 1; i <= n; i++)
    if (!num[i])
      if (place[i])
        neu++;
      else
        fix++;
  dp[0][0] = 1;
  for (int i = 0; i < fix; i++)
    for (int j = 0; j < n; j++) {
      if (j > 0) dp[i + 1][j - 1] = (dp[i + 1][j - 1] + j * dp[i][j]) % M;
      dp[i + 1][j] = (dp[i + 1][j] + (i - j) * dp[i][j]) % M;
      dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % M;
    }
  for (int i = fix; i < fix + neu; i++)
    for (int j = 0; j < n; j++) {
      if (j > 0) dp[i + 1][j - 1] = (dp[i + 1][j - 1] + j * dp[i][j]) % M;
      dp[i + 1][j] = (dp[i + 1][j] + (i - j + 1) * dp[i][j]) % M;
    }
  cout << dp[fix + neu][0] << "\n";
  return 0;
}
