#include <bits/stdc++.h>
using namespace std;
int fac[100010], inv[100010], n, A[100010];
int C(int m, int n) {
  if (m < n || n < 0) return 0;
  return (long long)fac[m] * inv[m - n] % 1000000007 * inv[n] % 1000000007;
}
struct QE {
  int p, a;
  bool operator<(const QE &ano) const { return a < ano.a; }
} qe[100010];
int mid(int m, int l, int r) {
  if (l > r) swap(l, r);
  return l < m && m < r;
}
int f[100010][2];
int power(int a, int b) {
  if (b == -1) return 1;
  if (b == 1) return a;
  if (b == 0) return 1;
  int t = power(a, b / 2);
  return b & 1 ? (long long)t * t % 1000000007 * a % 1000000007
               : (long long)t * t % 1000000007;
}
void Get(int i) {
  f[i][0] = f[i][1] = 0;
  int d = qe[i].a - qe[i - 1].a - 1;
  int u = abs(qe[i].p - qe[i - 1].p) + 1 - qe[i - 1].a - 1;
  if (qe[i - 1].p > qe[i].p)
    f[i][1] = (long long)f[i - 1][0] * C(d, u) % 1000000007;
  else
    f[i][0] = (long long)f[i - 1][1] * C(d, u) % 1000000007;
  u = abs(qe[i].p - qe[i - 1].p) - 1;
  if (qe[i].p > qe[i - 1].p)
    f[i][0] += (long long)f[i - 1][0] * C(d, u) % 1000000007,
        f[i][0] %= 1000000007;
  else
    f[i][1] += (long long)f[i - 1][1] * C(d, u) % 1000000007,
        f[i][1] %= 1000000007;
}
int main() {
  scanf("%d", &n);
  inv[0] = inv[1] = fac[0] = fac[1] = 1;
  for (int i = 2; i <= 100000; ++i)
    fac[i] = (long long)fac[i - 1] * i % 1000000007,
    inv[i] = (long long)inv[1000000007 % i] * (1000000007 - 1000000007 / i) %
             1000000007;
  for (int i = 2; i <= 100000; ++i)
    inv[i] = (long long)inv[i] * inv[i - 1] % 1000000007;
  int cnt_qe = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &A[i]);
    if (A[i]) qe[++cnt_qe] = (QE){i, A[i]};
  }
  sort(qe + 1, qe + cnt_qe + 1);
  if (!cnt_qe) {
    printf("%d\n", power(2, n - 1));
    return 0;
  }
  if (qe[1].p >= qe[1].a) f[1][0] = power(2, qe[1].a - 2);
  if (qe[1].a != 1 && n - qe[1].p + 1 >= qe[1].a)
    f[1][1] = power(2, qe[1].a - 2);
  for (int i = 2; i <= cnt_qe; ++i) {
    Get(i);
  }
  int ans = 0;
  if (qe[cnt_qe].a != n) {
    if (!A[1]) {
      qe[cnt_qe + 1] = (QE){1, n};
      Get(cnt_qe + 1);
      ans += f[cnt_qe + 1][1];
    }
    if (!A[n]) {
      qe[cnt_qe + 1] = (QE){n, n};
      Get(cnt_qe + 1);
      ans += f[cnt_qe + 1][0];
      ans %= 1000000007;
    }
  } else
    ans = (f[cnt_qe][0] + f[cnt_qe][1]) % 1000000007;
  printf("%d\n", ans);
  return 0;
}
