#include <bits/stdc++.h>
using namespace std;
int a[2010][2010], v1[2010], v2[2010], f[2010][2010];
const int mod = 1e9 + 7;
int main() {
  int n, x, num = 0, res = 0;
  cin >> n;
  for (register int i = 1; i <= n; i++) {
    cin >> x;
    if (x != -1) {
      v1[i] = v2[x] = 1;
      if (i == x) {
        cout << "0";
        return 0;
      }
    } else
      res++;
  }
  for (register int i = 1; i <= n; i++) a[i][i] = 1;
  for (register int i = 1; i <= n; i++)
    if (!v1[i]) {
      for (register int j = 1; j <= n; j++)
        if (!v2[j] && a[i][j]) num++;
    }
  f[0][0] = 1;
  for (register int i = 1; i <= n; i++)
    f[i][0] = (long long)f[i - 1][0] * i % mod;
  for (register int i = 1; i <= res; i++)
    for (register int j = 1; j <= num; j++)
      f[i][j] = (f[i][j - 1] - f[i - 1][j - 1] + mod) % mod;
  cout << f[res][num] << endl;
  return 0;
}
