#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long powmod(long long a, long long b) {
  if (b == 0) return 1LL;
  long long k = powmod(a, b / 2);
  if (b % 2 == 0) return (k * k) % MOD;
  return (((k * k) % MOD) * a) % MOD;
}
long long fact[200000];
long long nCr(long long n, long long r) {
  return (fact[n] * powmod((fact[r] * fact[n - r]) % MOD, MOD - 2)) % MOD;
}
int main() {
  fact[0] = 1;
  for (long long i = 1; i < 200000; i++) {
    fact[i] = (fact[i - 1] * i) % MOD;
  }
  long long n;
  cin >> n;
  long long seats[n];
  for (long long i = 0; i < n; i++) cin >> seats[i];
  for (long long i = 0; i < n; i++) seats[i]--;
  long long back[n];
  for (long long i = 0; i < n; i++) back[i] = -1;
  for (long long i = 0; i < n; i++)
    if (seats[i] >= 0) back[seats[i]] = i;
  long long num = 0;
  for (long long i = 0; i < n; i++)
    if (seats[i] >= 0) num++;
  if (num == 0) {
    cout << powmod(2LL, n - 1) << endl;
    return 0;
  }
  long long seat = -1;
  for (long long i = 0; i < n; i++) {
    if (back[i] >= 0) {
      seat = i;
      break;
    }
  }
  long long left, right;
  long long ans = 0;
  if (back[seat] - seat >= 0) {
    left = back[seat] - seat;
    right = back[seat];
    long long curans = 1;
    if (seat > 0) curans *= powmod(2, seat - 1);
    for (long long i = seat + 1; i < n; i++) {
      if (back[i] >= 0) {
        if (back[i] >= left && back[i] <= right) {
          curans = 0;
          break;
        }
        if (back[i] < left) {
          if (back[i] + i >= n) {
            curans = 0;
            break;
          }
          if (back[i] + i < right) {
            curans = 0;
            break;
          }
          curans =
              (curans * nCr(i + left - right - 1, left - back[i] - 1)) % MOD;
          left = back[i];
          right = back[i] + i;
        } else if (back[i] > right) {
          if (back[i] - i < 0) {
            curans = 0;
            break;
          }
          if (back[i] - i > left) {
            curans = 0;
            break;
          }
          curans =
              (curans * nCr(i + left - right - 1, back[i] - right - 1)) % MOD;
          left = back[i] - i;
          right = back[i];
        }
      }
    }
    curans = (curans * nCr(n - right + left - 1, left)) % MOD;
    ans = (ans + curans) % MOD;
  }
  if (back[seat] + seat < n && (seat > 0)) {
    left = back[seat];
    right = back[seat] + seat;
    long long curans = 1;
    if (seat > 0) curans *= powmod(2, seat - 1);
    for (long long i = seat + 1; i < n; i++) {
      if (back[i] >= 0) {
        if (back[i] >= left && back[i] <= right) {
          curans = 0;
          break;
        }
        if (back[i] < left) {
          if (back[i] + i >= n) {
            curans = 0;
            break;
          }
          if (back[i] + i < right) {
            curans = 0;
            break;
          }
          curans =
              (curans * nCr(i + left - right - 1, left - back[i] - 1)) % MOD;
          left = back[i];
          right = back[i] + i;
        } else if (back[i] > right) {
          if (back[i] - i < 0) {
            curans = 0;
            break;
          }
          if (back[i] - i > left) {
            curans = 0;
            break;
          }
          curans =
              (curans * nCr(i + left - right - 1, back[i] - right - 1)) % MOD;
          left = back[i] - i;
          right = back[i];
        }
      }
    }
    curans = (curans * nCr(n - right + left - 1, left)) % MOD;
    ans = (ans + curans) % MOD;
  }
  cout << ans << endl;
  return 0;
}
