#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const long long mod2 = 1000000007;
int a[2020];
long long p[2020];
long long c[2010][2010];
int vis[2010];
int main() {
  ios::sync_with_stdio(false);
  p[0] = 1;
  for (int i = 1; i <= 2001; i++) p[i] = p[i - 1] * i % mod;
  int n;
  while (cin >> n) {
    memset(vis, 0, sizeof(vis));
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    int con = 0, con2 = 0;
    for (int i = 1; i <= n; i++) {
      if (a[i] == -1)
        con++;
      else {
        vis[a[i]] = 1;
      }
    }
    for (int i = 1; i <= n; i++) {
      if (a[i] == -1 && vis[i] == 0) {
        con2++;
      }
    }
    c[0][0] = 1;
    for (int i = 0; i <= con + 1; i++) {
      c[i][0] = c[i][i] = 1;
      for (int j = 1; j < i; j++)
        c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
    }
    long long ans = p[con];
    int flag = 1;
    for (int i = 1; i <= con2; i++) {
      if (flag) {
        ans -= c[con2][i] * p[con - i] % mod2;
      } else {
        ans += c[con2][i] * p[con - i] % mod2;
      }
      flag ^= 1;
    }
    while (ans < 0) ans += mod, ans %= mod;
    cout << (ans + mod2) % mod2 << endl;
  }
}
