#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
int power(int a, int b, int m, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % m)
    if (b & 1) ans = 1LL * ans * a % m;
  return ans;
}
int a[2010], vst[2010], c[2010][2010], p[2010];
int main() {
  c[0][0] = 1;
  for (int i = 1; i < 2010; i++) c[0][i] = 0;
  c[1][0] = 1;
  c[1][1] = 1;
  for (int i = 2; i < 2010; i++) c[1][i] = 0;
  for (int j = 2; j < 2010; j++) {
    for (int i = 0; i < 2010; i++)
      c[j][i] = (c[j - 1][i - 1] + c[j - 1][i]) % 1000000007;
  }
  p[0] = 1;
  for (int i = 1; i < 2010; i++) p[i] = ((long long)p[i - 1] * i) % 1000000007;
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    vst[a[i]] = 1;
  }
  int r = 0, s = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] == -1 && vst[i] == 0) r++;
    if (a[i] == -1 && vst[i] == 1) s++;
  }
  int res = 0;
  for (int i = 0; i <= r; i++) {
    if (i % 2 == 0) res += ((long long)c[r][i] * p[r + s - i]) % 1000000007;
    if (i % 2 == 1)
      res += (1000000007 - ((long long)c[r][i] * p[r + s - i]) % 1000000007) %
             1000000007;
    res %= 1000000007;
  }
  printf("%d\n", res);
  return 0;
}
