#include <bits/stdc++.h>
using namespace std;
const int NN = 100100;
int c[NN], p[NN], fac[NN], num[NN];
const int mod = 1e9 + 7;
int power(int a, int b, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % mod)
    if (b & 1) ans = 1LL * ans * a % mod;
  return ans;
}
int C(int u, int v) {
  int ans = fac[u];
  ans = 1LL * ans * power(fac[v], mod - 2) % mod;
  ans = 1LL * ans * power(fac[u - v], mod - 2) % mod;
  return ans;
}
int sol(int n, int l, int r) {
  if (n <= 1) return 1;
  int nn = num[r] - num[l - 1];
  if (!nn) return power(2, n - 1);
  int val, P;
  for (int i = n; i; i--) {
    if (p[i]) {
      val = i;
      P = p[i];
      break;
    }
  }
  if (val == 1) {
    return C(n - 1, P - l);
  }
  int L = n - val;
  int ans = 0;
  if (L >= P - l) {
    int mm = num[P - 1] - num[l - 1];
    mm += num[r] - num[r - (L - P + l)];
    if (!mm)
      ans = (ans +
             1LL * C(L, P - l) * sol(val - 1, P + 1, r - (L - P + l)) % mod) %
            mod;
  }
  if (L >= r - P) {
    int mm = num[r] - num[P];
    mm += num[l + (L - r + P) - 1] - num[l - 1];
    if (!mm)
      ans = (ans +
             1LL * C(L, r - P) * sol(val - 1, l + (L - r + P), P - 1) % mod) %
            mod;
  }
  return ans;
}
int main() {
  fac[0] = 1;
  for (int i = 1; i <= 100000; i++) fac[i] = 1LL * fac[i - 1] * i % mod;
  int n;
  int nn = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", c + i);
    num[i] = num[i - 1];
    if (c[i]) p[c[i]] = i, num[i]++;
  }
  int ans = sol(n, 1, n);
  printf("%d\n", ans);
  return 0;
}
