#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
long long mypow(long long x, long long res) {
  if (!res) return 1;
  long long cur = mypow(x, res >> 1);
  cur = cur * cur % mod;
  if (res & 1) cur = cur * x % mod;
  return cur;
}
long long fac[maxn], inv[maxn];
void pre() {
  fac[0] = fac[1] = inv[0] = inv[1] = 1;
  for (int i = 2; i < maxn; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = ((mod - mod / i * inv[mod % i]) % mod + mod) % mod;
  }
  for (int i = 2; i < maxn; i++) inv[i] = inv[i] * inv[i - 1] % mod;
}
long long C(int m, int n) { return fac[m] * inv[n] % mod * inv[m - n] % mod; }
struct node {
  int rank, pos;
  friend bool operator<(node n1, node n2) { return n1.rank < n2.rank; }
} a[maxn];
int na;
long long ans;
void cal(int p) {
  int l = p, r = p, i = 1, pre = 1;
  if (a[1].rank == 1) i++;
  long long cur = 1;
  for (; i <= na; i++) {
    if (a[i].pos >= l && a[i].pos <= r) return;
    if (a[i].pos < l) {
      int len = l - a[i].pos - 1;
      int res = a[i].rank - pre - 1;
      if (res < len) return;
      cur = cur * C(res, len) % mod;
      pre = a[i].rank;
      l = a[i].pos;
      r += res - len;
      continue;
    }
    int len = a[i].pos - r - 1;
    int res = a[i].rank - pre - 1;
    if (res < len) return;
    cur = cur * C(res, len) % mod;
    pre = a[i].rank;
    r = a[i].pos;
    l -= res - len;
  }
  ans = (ans + cur) % mod;
}
int main() {
  pre();
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    if (!x) continue;
    a[++na].rank = x;
    a[na].pos = i;
  }
  a[++na].rank = n + 1;
  a[na].pos = n + 1;
  sort(a + 1, a + 1 + na);
  if (na == 1) {
    printf("%lld", mypow(2, n - 1));
    return 0;
  }
  if (a[1].rank == 1)
    cal(a[1].pos);
  else {
    for (int i = 1; i <= n; i++) cal(i);
  }
  printf("%lld", ans);
  return 0;
}
