#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, maxn = 100005;
int fact[maxn], inv[maxn];
void init(int n = 1e5) {
  fact[0] = 1;
  for (int i = 1; i <= n; i++)
    fact[i] = (long long)i * fact[i - 1] % 1000000007;
  inv[1] = 1;
  for (int i = 2; i <= n; i++)
    inv[i] = 1000000007 -
             (long long)(1000000007 / i) * inv[1000000007 % i] % 1000000007;
  inv[0] = 1;
  for (int i = 1; i <= n; i++)
    inv[i] = (long long)inv[i - 1] * inv[i] % 1000000007;
}
int C(int n, int m) {
  return (long long)fact[n] * inv[m] % 1000000007 * inv[n - m] % 1000000007;
}
struct node {
  int pos, val;
  bool operator<(const node &b) const { return val < b.val; }
} a[maxn];
void add(int &x, int y) {
  x = x + y >= 1000000007 ? x + y - 1000000007 : x + y;
}
int n, m;
int Solve(int pos, int i) {
  int l = pos, r = pos, ans = 1, pre = 1;
  for (; i < m; i++) {
    if (a[i].pos < l) {
      int dval = a[i].val - pre - 1, dpos = l - a[i].pos - 1;
      if (dpos > dval) return 0;
      ans = (long long)ans * C(dval, dpos) % 1000000007;
      l = a[i].pos, r += dval - dpos, pre = a[i].val;
    } else if (a[i].pos > r) {
      int dval = a[i].val - pre - 1, dpos = a[i].pos - r - 1;
      if (dpos > dval) return 0;
      ans = (long long)ans * C(dval, dpos) % 1000000007;
      r = a[i].pos, l -= dval - dpos, pre = a[i].val;
    } else
      return 0;
  }
  return ans;
}
int main() {
  init();
  while (~scanf("%d", &n)) {
    m = 0;
    for (int i = 1; i <= n; i++) {
      int temp;
      scanf("%d", &temp);
      if (temp) a[m++] = (node){i, temp};
    }
    a[m++] = (node){n + 1, n + 1};
    sort(a, a + m);
    int ans = 0;
    if (a[0].val == 1)
      add(ans, Solve(a[0].pos, 1));
    else
      for (int i = 1; i <= n; i++) add(ans, Solve(i, 0));
    printf("%d\n", ans);
  }
  return 0;
}
