#include <bits/stdc++.h>
using namespace std;
const int p = (int)1e9 + 7;
const int maxn = (int)2e5 + 10;
int a[maxn];
int perm[maxn];
int two[maxn];
long long fact[maxn];
long long ofact[maxn];
long long mpow(long long x, long long n) {
  if (!n) return 1;
  long long y = mpow(x, n / 2);
  y = (y * y) % p;
  if (n & 1) y = (y * x) % p;
  return y;
}
long long obr(int x) { return mpow(x, p - 2); }
long long get_c(int n, int k) {
  assert(n >= 0 && k >= 0 && k <= n);
  return (((fact[n] * ofact[k]) % p) * ofact[n - k]) % p;
}
long long get_ans(int af, int at, int bf, int bt) {
  if (af > bf || bf > bt || bt > at) {
    return 0;
  }
  int l = bf - af;
  int r = at - bt;
  cerr << af << " " << bf << " " << bt << " " << at << " " << get_c(r + l, l)
       << endl;
  return get_c(r + l, l);
}
int main() {
  srand(time(NULL));
  two[0] = 1;
  fact[0] = 1;
  ofact[0] = 1;
  for (int i = 1; i < maxn; i++) {
    two[i] = two[i - 1] * 2;
    two[i] %= p;
    fact[i] = fact[i - 1] * i;
    fact[i] %= p;
    ofact[i] = (ofact[i - 1] * obr(i)) % p;
  }
  int n;
  scanf("%d", &n);
  vector<int> ind;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]), a[i]--;
    if (a[i] >= 0) {
      perm[a[i]] = i;
      ind.push_back(a[i]);
    }
  }
  sort((ind).begin(), (ind).end());
  if (!ind.size()) {
    printf("%d\n", two[n - 1]);
  } else {
    int q = ind[0];
    int fl = perm[q] - q, fr = perm[q];
    long long fc = (fl >= 0 && fr < n) ? (q > 0 ? two[q - 1] : 1) : 0;
    int sl = perm[q], sr = perm[q] + q;
    long long sc = (sl >= 0 && sr < n) ? (q > 0 ? two[q - 1] : 1) : 0;
    for (int i = 1; i < ind.size(); i++) {
      q = ind[i];
      int newfl = perm[q] - q, newfr = perm[q];
      int newsl = perm[q], newsr = perm[q] + q;
      long long newfc = fc * get_ans(newfl, newfr - 1, fl, fr);
      if (fl != sl || fr != sr) newfc += sc * get_ans(newfl, newfr - 1, sl, sr);
      long long newsc = fc * get_ans(newsl + 1, newsr, fl, fr);
      if (fl != sl || fr != sr) newsc += sc * get_ans(newsl + 1, newsr, sl, sr);
      fl = newfl, fr = newfr, fc = newfc % p;
      sl = newsl, sr = newsr, sc = newsc % p;
    }
    long long ans = 0;
    if (fc > 0) {
      ans += fc * get_ans(0, n - 1, fl, fr);
    }
    if (fl != sl || fr != sr) {
      if (sc > 0) {
        ans += sc * get_ans(0, n - 1, sl, sr);
      }
    }
    printf("%d\n", (int)(ans % p));
  }
  return 0;
}
