#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;
}
inline void getint(int &first) {
  char c;
  while (c = getchar(), c > '9' || c < '0')
    ;
  for (first = 0; c >= '0' && c <= '9'; c = getchar())
    first = (first << 1) + (first << 3) + c - '0';
}
inline void print(int first) {
  if (first < 10) {
    putchar('0' + first);
    return;
  }
  print(first / 10);
  putchar(first % 10 + '0');
}
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[2040], vst[2040], ans[2040][2040], p[2040];
int main() {
  int n;
  getint(n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = 1; i <= n; i++)
    if (a[i] != -1) vst[a[i]] = 1;
  int nn = 0, mm = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] == -1 && !vst[i]) nn++;
    mm += a[i] == -1;
  }
  mm -= nn;
  for (int i = p[0] = 1; i <= n; i++)
    p[i] = (long long)p[i - 1] * i % 1000000007;
  for (int i = 0; i <= n; i++) ans[0][i] = p[i];
  for (int i = 1; i <= n; i++)
    ans[1][i] = (p[i + 1] - p[i] + 1000000007) % 1000000007;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      int &a = ans[i][j];
      a = (long long)ans[i - 1][j] * j % 1000000007;
      a += (long long)ans[i - 2][j] * (i - 1) % 1000000007;
      a %= 1000000007;
      a += (long long)ans[i - 1][j] * (i - 1) % 1000000007;
      a %= 1000000007;
    }
  }
  print(ans[nn][mm]);
  return 0;
}
