#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = 3.1415926535897932384626433832795;
template <class T>
T sqr(T x) {
  return x * x;
}
template <class T>
T abs(T x) {
  return x < 0 ? -x : x;
}
const int MAXN = 120000;
const long long p = 1000 * 1000 * 1000 + 7;
long long fact[MAXN], ans[MAXN][2];
int a[MAXN];
vector<pair<int, int> > ev;
long long sum(long long a, long long b) { return (a + b) % p; }
long long mult(long long a, long long b) { return (a * b) % p; }
long long deg(long long a, long long n) {
  if (n == 0) {
    return 1;
  }
  long long ans = deg(a, n / 2);
  ans = mult(ans, ans);
  if ((n % 2) == 1) {
    ans = mult(ans, a);
  }
  return ans;
}
long long inv(long long a) { return deg(a, p - 2); }
long long binomial(long long n, long long k) {
  long long ans = mult(fact[n - k], fact[k]);
  ans = inv(ans);
  ans = mult(ans, fact[n]);
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] > 0) {
      ev.push_back(make_pair(n - a[i], i));
    }
  }
  if (ev.size() > 0) {
    sort(ev.begin(), ev.end());
  }
  fact[0] = 1;
  for (int i = 1; i <= n; ++i) {
    fact[i] = mult(fact[i - 1], i);
  }
  int t_old = -1, t = -1, pl, pl_old;
  if (ev.size() > 0) {
    t = ev[0].first;
    pl = ev[0].second;
    if (t >= pl) {
      ans[0][0] = binomial(t, pl);
    }
    if (t >= n - 1 - pl) {
      ans[0][1] = binomial(t, n - 1 - pl);
    }
    t_old = t;
    pl_old = pl;
  }
  for (int i = 1; i < ev.size(); ++i) {
    t = ev[i].first;
    pl = ev[i].second;
    int left = -1;
    int right = -1;
    if (pl > pl_old && pl < n - (t_old - pl_old)) {
      left = pl_old + 1;
      right = t_old - pl_old;
      ans[i][0] = ans[i - 1][0];
      ans[i][1] = ans[i - 1][0];
    } else if (pl < pl_old && pl >= t_old - (n - 1 - pl_old)) {
      left = t_old - (n - 1 - pl_old);
      right = n - pl_old;
      ans[i][0] = ans[i - 1][1];
      ans[i][1] = ans[i - 1][1];
    }
    if (left != -1) {
      ans[i][0] = mult(ans[i][0], binomial(t - t_old - 1, pl - left));
      ans[i][1] = mult(ans[i][1], binomial(t - t_old - 1, n - 1 - pl - right));
    }
    t_old = t;
    pl_old = pl;
  }
  long long fin_ans = 1;
  if (t_old < n - 1) {
    if (ev.size() > 0) {
      fin_ans = sum(ans[ev.size() - 1][0], ans[ev.size() - 1][1]);
    }
    if (t_old < n - 1) {
      fin_ans = mult(fin_ans, deg(2, n - 2 - t_old));
    }
  } else {
    fin_ans = ans[ev.size() - 1][0];
  }
  cout << fin_ans;
  return 0;
}
