#include <bits/stdc++.h>
using namespace std;
int n, i, j;
int v[2004];
int fact[2004];
bool seen[2004];
int dp[2004][2004];
int getFact(int x) {
  if (fact[x]) return fact[x];
  int res = 1;
  for (int i = 2; i <= x; i++) res = (1LL * res * i) % 1000000007;
  return fact[x] = res;
}
int memo(int x, int y) {
  int res;
  if (dp[x][y] != -1) return dp[x][y];
  if (y == 1)
    res = 1LL * x * getFact(x) % 1000000007;
  else if (y == 0)
    res = getFact(x);
  else
    res = (1LL * (y - 1) * memo(x + 1, y - 2) % 1000000007 +
           1LL * x * memo(x, y - 1) % 1000000007) %
          1000000007;
  return dp[x][y] = res;
}
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &v[i]);
    if (v[i] != -1) seen[v[i]] = true;
  }
  memset(dp, -1, sizeof(dp));
  int x = 0, y = 0;
  for (i = 1; i <= n; i++)
    if (v[i] == -1)
      if (seen[i])
        x++;
      else
        y++;
  printf("%d", memo(x, y));
  return 0;
}
