#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 20;
const int mod = 1e9 + 7;
int n, m, tot;
long long ans, cz[N], cm[N];
long long pow(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret = ret * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ret;
}
void init() {
  cz[0] = 1;
  cm[0] = 1;
  for (int i = 1; i < N; i++)
    cz[i] = cz[i - 1] * i % mod, cm[i] = pow(cz[i], 1ll * (mod - 2));
}
long long C(int n, int m) {
  if (n < m) return 1;
  return cz[n] * cm[m] % mod * cm[n - m] % mod;
}
struct Node {
  int pos, rnk;
  bool operator<(const Node &d) const { return rnk < d.rnk; }
} a[N];
void solve(int pos) {
  long long ret = 1;
  int l = pos, r = pos, lst = 1, sum, sub;
  for (int i = (a[1].rnk == 1 ? 2 : 1); i <= tot; i++) {
    if (a[i].pos < l) {
      sum = l - a[i].pos - 1;
      sub = a[i].rnk - lst - 1;
      if (sub < sum) return;
      ret = ret * C(sub, sum) % mod;
      lst = a[i].rnk;
      l = a[i].pos;
      r += sub - sum;
    } else if (a[i].pos > r) {
      sum = a[i].pos - r - 1;
      sub = a[i].rnk - lst - 1;
      if (sub < sum) return;
      ret = ret * C(sub, sum) % mod;
      lst = a[i].rnk;
      r = a[i].pos;
      l -= sub - sum;
    } else
      return;
  }
  ans = (ans + ret) % mod;
}
int main() {
  scanf("%d", &n);
  init();
  for (int i = 1, x; i <= n; i++) {
    scanf("%d", &x);
    if (x) a[++tot] = (Node){i, x};
  }
  if (!tot) {
    printf("%lld", pow(2ll, 1ll * (n - 1)));
    return 0;
  }
  a[++tot] = (Node){n + 1, n + 1};
  sort(a + 1, a + tot + 1);
  if (a[1].rnk == 1)
    solve(a[1].pos);
  else
    for (int i = 1; i <= n; i++) solve(i);
  printf("%lld", ans);
  return 0;
}
