#include <bits/stdc++.h>
using namespace std;
int n, tot;
long long ans;
struct node {
  int val;
  int pos;
  bool operator<(const node& a) const { return val < a.val; }
} a[100010];
long long fenzi[100010];
long long fenmu[100010];
long long pow_mod(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b % 2 == 1) ans = ans * a % 1000000007;
    a = a * a % 1000000007;
    b /= 2;
  }
  return ans % 1000000007;
}
long long C(int a, int b) {
  if (a < b) return 0;
  return (fenzi[a] * fenmu[b] % 1000000007) * fenmu[a - b] % 1000000007;
}
void init() {
  fenzi[0] = 1;
  fenmu[0] = 1;
  for (int i = 1; i < 100010; i++) {
    fenzi[i] = fenzi[i - 1] * i % 1000000007;
    fenmu[i] = pow_mod(fenzi[i], 1000000007 - 2);
  }
}
void solve(int po) {
  int l = po, r = po;
  int vv = 1;
  int i = 0;
  if (a[i].val == 1) i++;
  long long ret = 1;
  int len, tmp;
  for (; i < tot; i++) {
    if (a[i].pos < l) {
      len = l - a[i].pos - 1;
      tmp = a[i].val - vv - 1;
      if (tmp < len) return;
      ret = ret * C(tmp, len) % 1000000007;
      r += tmp - len;
      l = a[i].pos;
      vv = a[i].val;
    } else if (a[i].pos > r) {
      len = a[i].pos - r - 1;
      tmp = a[i].val - vv - 1;
      if (tmp < len) return;
      ret = ret * C(tmp, len) % 1000000007;
      l -= tmp - len;
      r = a[i].pos;
      vv = a[i].val;
    } else {
      return;
    }
  }
  ans = (ans + ret) % 1000000007;
}
int main() {
  init();
  while (~scanf("%d", &n)) {
    int x;
    tot = 0;
    ans = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &x);
      if (x) {
        a[tot].val = x;
        a[tot].pos = i;
        tot++;
      }
    }
    a[tot].val = n + 1;
    a[tot].pos = n + 1;
    tot++;
    if (tot == 1) {
      ans = pow_mod(2, n - 1);
    } else {
      sort(a, a + tot);
      if (a[0].val == 1) {
        solve(a[0].pos);
      } else {
        for (int i = 1; i <= n; i++) {
          solve(i);
        }
      }
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
