#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j;
  int x;
  int mark;
  int fl[2010];
  int used[2010];
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    fl[i] = 0;
    used[i] = 0;
  }
  mark = 0;
  for (i = 1; i <= n; i++) {
    scanf("%d", &x);
    if (-1 == x) {
      fl[i] = 1;
      mark++;
    } else
      used[x] = 1;
  }
  int k;
  k = 0;
  for (i = 1; i <= n; i++) {
    if (0 == used[i] && 1 == fl[i]) k++;
  }
  n = mark;
  static int fact[2010];
  fact[0] = 1;
  for (i = 1; i <= n; i++) fact[i] = int((fact[i - 1] * 1ll * i) % 1000000007);
  static int cnk[2010][2010];
  cnk[0][0] = 1;
  for (i = 1; i <= k; i++) {
    cnk[i][0] = 1;
    cnk[i][i] = 1;
    for (j = 1; j < i; j++) {
      cnk[i][j] = (cnk[i - 1][j] + cnk[i - 1][j - 1]) % 1000000007;
    }
  }
  int r = 0;
  long long buf;
  for (i = 0; i <= k; i++) {
    if (i & 1) {
      buf = cnk[k][i] * 1ll * fact[n - i];
      buf %= 1000000007;
      if (r < buf) r += 1000000007;
      r = (r - buf) % 1000000007;
    } else
      r = (r + cnk[k][i] * 1ll * fact[n - i]) % 1000000007;
  }
  printf("%d\n", r);
  return 0;
}
