#include <bits/stdc++.h>
using namespace std;
using ll = long long;
inline ll read() {
  ll x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const ll mod = 1e9 + 7, N = 1e5 + 10;
ll n, fac[N], inv[N], ans, cnt;
pair<ll, ll> a[N];
inline ll ksm(ll x, ll y) {
  ll res(1);
  for (; y; y >>= 1, x = x * x % mod)
    if (y & 1) res = res * x % mod;
  return res;
}
inline ll calc(ll x, ll y) { return fac[x] * inv[y] % mod * inv[x - y] % mod; }
inline void find(ll x, ll y) {
  ll l(y), r(y), sum(1);
  for (ll i = x; i <= cnt; i++) {
    ll num = a[i].first - a[i - 1].first - 1, dis = a[i].second;
    if (l <= dis && dis <= r) return;
    if (dis < l) {
      if (l - dis - 1 > num) return;
      ll tmp1 = l - dis - 1, tmp2 = num - tmp1;
      l = dis;
      r = r + tmp2;
      sum = sum * calc(num, tmp1) % mod;
    } else {
      if (dis - r - 1 > num) return;
      ll tmp1 = dis - r - 1, tmp2 = num - tmp1;
      l = l - tmp2;
      r = dis;
      sum = sum * calc(num, tmp1) % mod;
    }
  }
  ans = (ans + sum) % mod;
}
int main() {
  n = read();
  for (ll i = 1; i <= n; i++) {
    ll x = read();
    if (!x) continue;
    a[++cnt].first = x;
    a[cnt].second = i;
  }
  a[++cnt].first = n + 1;
  a[cnt].second = n + 1;
  sort(a + 1, a + cnt + 1);
  fac[0] = 1;
  inv[0] = 1;
  for (ll i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % mod;
  for (ll i = 1; i <= n; i++) inv[i] = ksm(fac[i], mod - 2);
  a[0].first = 1;
  if (a[1].first == 1)
    find(2, a[1].second);
  else
    for (ll i = 1; i <= n; i++) find(1, i);
  printf("%lld\n", ans);
  return 0;
}
