#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 3;
const int MOD = (int)1e9 + 7;
int is[MAXN], pre[MAXN], NEXT[MAXN];
long long f[MAXN], jie[MAXN];
void init(int n) {
  jie[0] = 1;
  for (int i = 1; i <= n; i++) jie[i] = jie[i - 1] * i % MOD;
  int now = -1;
  for (int i = 1; i <= n; i++) {
    pre[i] = now;
    if (is[i]) now = i;
  }
  now = -1;
  for (int i = n; i > 0; i--) {
    NEXT[i] = now;
    if (is[i]) now = i;
  }
}
long long qp(long long x, long long y) {
  long long res = 1;
  while (y) {
    if (y & 1) res = res * x % MOD;
    x = x * x % MOD;
    y >>= 1;
  }
  return res;
}
long long get_c(long long x, long long y) {
  if (y < 0 || x < y) return 0;
  if (y == 0 || y == x) return 1;
  return jie[x] * qp(jie[y] * jie[x - y] % MOD, MOD - 2) % MOD;
}
long long solve(int n, bool flag) {
  if (!flag) return qp(2, n - 1);
  init(n);
  int L = n + 1, R = 0;
  for (int i = 1; i <= n; i++) {
    if (!is[i]) continue;
    if (L <= is[i] && R >= is[i]) return 0;
    if (pre[i] == -1 && NEXT[i] == -1) {
      long long ans = 0, now;
      for (int x = 0; x < is[i]; x++) {
        now = get_c(i - 1, x) * get_c(n - i, is[i] - x - 1) % MOD;
        if (x > 1)
          ans = (ans + now * 2 % MOD) % MOD;
        else
          ans = (ans + now) % MOD;
      }
      return ans;
    } else if (pre[i] > 0) {
      f[i] = f[pre[i]];
      if (is[i] > is[pre[i]])
        R++;
      else
        L--;
      if (NEXT[i] == -1) {
        return f[i] * get_c(n - i, L - 1) % MOD;
      } else {
        if (is[NEXT[i]] > R) {
          f[i] = f[i] * get_c(NEXT[i] - i - 1, is[NEXT[i]] - R - 1) % MOD;
          R = is[NEXT[i]] - 1;
          L = R + 2 - NEXT[i];
        } else {
          f[i] = f[i] * get_c(NEXT[i] - i - 1, L - is[NEXT[i]] - 1) % MOD;
          L = is[NEXT[i]] + 1;
          R = L + NEXT[i] - 2;
        }
      }
    } else {
      if (is[i] < is[NEXT[i]]) {
        R = is[NEXT[i]] - 1;
        L = R + 2 - NEXT[i];
      } else {
        L = is[NEXT[i]] + 1;
        R = L + NEXT[i] - 2;
      }
      int cnt = abs(is[NEXT[i]] - is[i]);
      f[i] = 0;
      if (i == 1) {
        f[i] = get_c(NEXT[i] - 2, R - is[i]);
      } else {
        if (i - 1 <= is[i] - L)
          f[i] = qp(2, i - 2) * get_c(NEXT[i] - i - 1, is[i] - L - i + 1) % MOD;
        if (i - 1 <= R - is[i])
          (f[i] += qp(2, i - 2) * get_c(NEXT[i] - i - 1, R - is[i] - i + 1) %
                   MOD) %= MOD;
      }
    }
  }
  return -1;
}
int main() {
  int n, u;
  bool flag = false;
  scanf("%d", &n);
  memset(is, 0, sizeof is);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &u);
    if (u) {
      is[u] = i;
      flag = true;
    }
  }
  printf("%d\n", (int)solve(n, flag));
  return 0;
}
