#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 5;
long long fact[M];
long long inv[M];
int ar[M];
long long bigmod(long long b, long long p);
long long nCr(int n, int r);
long long solve(int l, int r);
int main() {
  fact[0] = 1ll;
  inv[0] = bigmod(fact[0], 1000000007 - 2);
  for (int i = 1; i <= 1e5; i++) {
    fact[i] = (fact[i - 1] * (long long)i) % 1000000007;
    inv[i] = bigmod(fact[i], 1000000007 - 2) % 1000000007;
  }
  int n, cnt = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &ar[i]);
    if (!ar[i]) {
      cnt++;
    }
  }
  if (cnt == n) {
    printf("%lld\n", bigmod(2, n - 1));
    return 0;
  }
  long long get = solve(1, n);
  get %= 1000000007;
  if (get < 0ll) {
    get += 1000000007;
  }
  printf("%lld\n", get);
  return 0;
}
long long bigmod(long long b, long long p) {
  long long ret = 1ll;
  for (; p; p >>= 1) {
    if (p & 1ll) {
      ret = (ret * b) % 1000000007;
    }
    b = (b * b) % 1000000007;
  }
  return ret;
}
long long nCr(int n, int r) {
  if (r > n) {
    return 0ll;
  }
  if (r == 0 || r == n) {
    return 1ll;
  }
  long long ret = (fact[n] * inv[r]) % 1000000007;
  ret = (ret * inv[n - r]) % 1000000007;
  return ret;
}
long long solve(int l, int r) {
  if (l == r && ar[l] == 0) {
    return 1ll;
  }
  int x = l, y = r;
  while (x <= r && ar[x] == 0) {
    x++;
  }
  while (y >= l && ar[y] == 0) {
    y--;
  }
  if (x > y) {
    return bigmod(2, r - l);
  }
  long long ans = 0ll;
  if (x == y && ar[x] == 1) {
    ans = nCr(r - l, x - l) % 1000000007;
    return ans;
  }
  if (ar[x] >= ar[y]) {
    int lft = x + 1, rgt = x + ar[x] - 1;
    if (rgt >= y && rgt <= r) {
      ans = (ans + ((solve(lft, rgt) % 1000000007) *
                    (nCr(r - l - (rgt - lft + 1), r - rgt) % 1000000007)) %
                       1000000007) %
            1000000007;
    }
  }
  if (ar[y] >= ar[x]) {
    int rgt = y - 1, lft = y - ar[y] + 1;
    if (lft <= x && lft >= l) {
      ans = (ans + ((solve(lft, rgt) % 1000000007) *
                    (nCr(r - l - (rgt - lft + 1), r - rgt - 1) % 1000000007)) %
                       1000000007) %
            1000000007;
    }
  }
  return ans;
}
