#include <bits/stdc++.h>
using namespace std;
long long pwr(long long base, long long p, long long mod = (1000000007LL)) {
  long long ans = 1;
  while (p) {
    if (p & 1) ans = (ans * base) % mod;
    base = (base * base) % mod;
    p /= 2;
  }
  return ans;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int n, arr[2002];
bool ele_used[2002], pos_used[2002];
long long DP[2002][2002][2];
long long dp(int rem_ele, int super_pos, bool start_new_chain) {
  if (super_pos < 0) return 0;
  if (rem_ele == 0) return 1;
  long long &ans = DP[rem_ele][super_pos][start_new_chain];
  if (ans != -1) return ans;
  ans = 0;
  if (start_new_chain) {
    ans = (ans + (rem_ele - 1) * dp(rem_ele - 1, super_pos + 1, false)) %
          (1000000007LL);
    ans = (ans + (super_pos)*dp(rem_ele - 1, super_pos, true)) % (1000000007LL);
    return ans;
  } else {
    ans = (ans + (rem_ele - 1) * dp(rem_ele - 1, super_pos, false)) %
          (1000000007LL);
    ans = (ans + super_pos * dp(rem_ele - 1, super_pos - 1, true)) %
          (1000000007LL);
    return ans;
  }
  assert(0);
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    if (arr[i] != -1) {
      ele_used[arr[i]] = pos_used[i] = true;
    }
  }
  int constrained = 0, super_ele = 0, super_pos = 0;
  for (int i = 1; i <= n; i++)
    if (!ele_used[i] && !pos_used[i])
      constrained++;
    else if (ele_used[i] && !pos_used[i])
      super_pos++;
    else if (pos_used[i] && !ele_used[i])
      super_ele++;
  memset(DP, -1, sizeof(DP));
  long long ans = dp(constrained, super_pos, true);
  while (super_ele > 0) {
    ans = (ans * super_ele) % (1000000007LL);
    super_ele--;
  }
  cout << ans;
  return 0;
}
