#include <bits/stdc++.h>
#pragma comment(linker, "/stack:16777216")
using namespace std;
const int INF = 1000000000;
const int MAX = 200000;
const int MAX2 = 7000;
const int BASE = 1000000000;
int n, m;
int A[MAX];
int B[MAX];
pair<int, int> P[MAX][2];
int R[MAX][2];
int I[MAX];
long long F1[MAX];
long long F2[MAX];
long long Pow(long long a, long long b) {
  long long res = 1;
  while (b > 0)
    if (b % 2 == 0) {
      b /= 2;
      a = (a * a) % 1000000007;
    } else {
      --b;
      res = (res * a) % 1000000007;
    }
  return res;
}
long long C(int n, int k) {
  if (k > n) return 0;
  if (n < 0 || k < 0) return 0;
  long long res = F1[n];
  res = (res * F2[k]) % 1000000007;
  res = (res * F2[n - k]) % 1000000007;
  return res;
}
int main() {
  F1[0] = F2[0] = 1;
  for (int i = (1); i < (MAX); ++i) {
    F1[i] = (F1[i - 1] * i) % 1000000007;
    F2[i] = Pow(F1[i], 1000000007 - 2);
  }
  scanf("%d", &n);
  memset(B, -1, sizeof(B));
  for (int i = (0); i < (n); ++i) {
    int x;
    scanf("%d", &x);
    --x;
    A[i] = x;
    if (x != -1) B[x] = i;
  }
  for (int i = (0); i < (n + 1); ++i)
    for (int j = (0); j < (2); ++j) P[i][j] = make_pair(-1, -1);
  m = 1;
  P[0][0] = make_pair(-1, n - 1);
  P[0][1] = make_pair(-1, -1);
  I[0] = n;
  for (int i = (n)-1; i >= (0); --i) {
    int x = B[i];
    if (x == -1) continue;
    int cnt = n - i - 1;
    if (cnt >= x) P[m][0] = make_pair(x, n - (cnt - x) - 1);
    if (cnt >= n - x - 1) P[m][1] = make_pair(cnt - (n - x - 1), x);
    if (P[m][0] == P[m][1]) P[m][1] = make_pair(-1, -1);
    I[m] = i;
    ++m;
  }
  long long res = 0;
  R[0][0] = 1;
  for (int i = (1); i < (m); ++i)
    for (int j = (0); j < (2); ++j) {
      int l = P[i][j].first;
      int r = P[i][j].second;
      if (l == -1 && r == -1) continue;
      if (l > r) continue;
      for (int k = (0); k < (2); ++k) {
        int ll = P[i - 1][k].first;
        int rr = P[i - 1][k].second;
        if (ll == -1 && rr == -1) continue;
        if (ll > rr) continue;
        if (k == 0)
          ++ll;
        else
          --rr;
        if (ll <= l && rr >= r) {
          int cnt = I[i - 1] - I[i] - 1;
          int a = l - ll;
          int b = rr - r;
          R[i][j] += (R[i - 1][k] * C(cnt, a)) % 1000000007;
          R[i][j] %= 1000000007;
        }
      }
    }
  res = (R[m - 1][0] + R[m - 1][1]) % 1000000007;
  int cnt = 0;
  while (cnt < n && B[cnt] == -1) ++cnt;
  for (int i = (0); i < (cnt - 1); ++i) res = (res * 2) % 1000000007;
  res %= 1000000007;
  printf("%d\n", res);
  return 0;
}
