#include <bits/stdc++.h>
using namespace std;
const long long MO = 1000000007ll;
const int MAXN = 100010;
int n, top, x;
pair<int, int> a[MAXN];
long long ans;
long long quc[MAXN];
long long cuq[MAXN];
long long Pow(long long a, long long b) {
  long long ret = 1;
  for (; b; b >>= 1) {
    if (b % 2ll) ret = ret * a % MO;
    a = a * a % MO;
  }
  return ret;
}
long long C(int a, int b) { return quc[a] * cuq[b] % MO * cuq[a - b] % MO; }
void Work(int st, int pos) {
  int l = pos, r = pos;
  long long now = 1;
  for (int i = st; i <= top; ++i) {
    int num = a[i].first - a[i - 1].first - 1, y = a[i].second;
    if ((l <= y) && (y <= r)) return;
    if (y < l) {
      if (l - y - 1 > num) return;
      int tmp1 = l - y - 1, tmp2 = num - tmp1;
      l = y;
      r = l + a[i].first - 1;
      now = now * C(tmp1 + tmp2, tmp1) % MO;
    } else {
      if (y - r - 1 > num) return;
      int tmp1 = y - r - 1, tmp2 = num - tmp1;
      r = y;
      l = r - a[i].first + 1;
      now = now * C(tmp1 + tmp2, tmp1) % MO;
    }
  }
  ans = (ans + now) % MO;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &x);
    if (x) {
      a[++top].first = x;
      a[top].second = i;
    }
  }
  a[++top].first = n + 1;
  a[top].second = n + 1;
  ++n;
  sort(a + 1, a + top + 1);
  quc[0] = 1;
  cuq[0] = 1;
  for (int i = 1; i <= n; ++i) quc[i] = quc[i - 1] * i % MO;
  for (int i = 1; i <= n; ++i) cuq[i] = Pow(quc[i], MO - 2);
  a[0].first = 1;
  if (a[1].first == 1)
    Work(2, a[1].second);
  else
    for (int i = 1; i <= n; ++i) Work(1, i);
  printf("%I64d\n", ans);
  return 0;
}
