#include <bits/stdc++.h>
using namespace std;
const int N = 2050;
const int mod = 1e9 + 7;
int a[N], vis[N], n;
int dp[N];
int main() {
  while (scanf("%d", &n) != -1) {
    memset(vis, 0, sizeof vis);
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &a[i]);
      if (a[i] != -1) vis[a[i]] = 1;
    }
    int x = 0, y = 0;
    for (int i = 1; i <= n; ++i)
      if (a[i] == -1) {
        if (!vis[i])
          x++;
        else
          y++;
      }
    dp[0] = 1;
    for (int i = 1; i <= y; ++i) dp[0] = 1ll * dp[0] * i % mod;
    dp[1] = 1ll * y * dp[0] % mod;
    for (int i = 2; i <= x; ++i)
      dp[i] =
          (1ll * y * dp[i - 1] + 1ll * (i - 1) * (dp[i - 1] + dp[i - 2])) % mod;
    printf("%d\n", dp[x]);
  }
  return 0;
}
