#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 2005;
const int mod = 1000000007;
int n;
int a[maxn];
bool vis[maxn];
bool in[maxn];
unsigned long long f[maxn][maxn];
bool g[maxn][maxn];
unsigned long long A[maxn];
void init() {
  A[0] = A[1] = 1;
  for (int i = 2; i < maxn; i++) {
    A[i] = (A[i - 1] * i) % mod;
  }
}
unsigned long long dfs(int x, int y) {
  if (g[x][y]) return f[x][y];
  if (y == 0) {
    g[x][y] = 1;
    return f[x][y] = A[x];
  }
  if (y == 1) {
    g[x][y] = 1;
    return f[x][y] = (x * dfs(x, y - 1)) % mod;
  }
  g[x][y] = 1;
  return f[x][y] = (x * dfs(x, y - 1) + (y - 1) * dfs(x + 1, y - 2)) % mod;
}
int main() {
  init();
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] != -1) {
      in[i] = 1;
      vis[a[i]] = 1;
    }
  }
  int cnt1 = 0, cnt2 = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    if (in[i])
      cnt1++;
    else
      cnt2++;
  }
  printf("%I64d\n", dfs(cnt1, cnt2));
  return 0;
}
