#include <bits/stdc++.h>
using namespace std;
const int SIZE = 2002;
const int MOD = 1e9 + 7;
int a[SIZE], fact[SIZE];
int dp[SIZE][SIZE];
bool vis[SIZE][SIZE];
bool mark[SIZE];
int solve(int cnt1, int cnt2) {
  if (cnt2 < 0) return 0;
  if (vis[cnt1][cnt2]) return dp[cnt1][cnt2];
  int &ret = dp[cnt1][cnt2];
  if (cnt2 == 0)
    ret = fact[cnt1];
  else {
    ret = (long long)(cnt2 - 1) * solve(cnt1 + 1, cnt2 - 2) % MOD;
    ret += (long long)cnt1 * solve(cnt1, cnt2 - 1) % MOD;
    ret %= MOD;
  }
  vis[cnt1][cnt2] = true;
  return ret;
}
int main() {
  int n;
  scanf("%d", &(n));
  for (int i = 0; i < n; ++i) scanf("%d", &(a[i]));
  fact[0] = 1;
  for (int i = 1; i <= n; ++i) fact[i] = ((long long)fact[i - 1] * i) % MOD;
  for (int i = 0; i < n; ++i)
    if (a[i] != -1) mark[a[i]] = true;
  int cnt1 = 0, cnt2 = 0;
  for (int i = 1; i <= n; ++i)
    if (!mark[i]) {
      if (a[i - 1] == -1)
        cnt2++;
      else
        cnt1++;
    }
  printf("%d\n", solve(cnt1, cnt2));
  return 0;
}
