#include <bits/stdc++.h>
using namespace std;
long long powr(long long x, long long y, long long mod);
long long comb(int n, int c);
long long fn();
long long gn(int x);
int check(int start, int e);
long long fact[100009];
const long long mod = 1000000007;
int n, y = 0;
pair<int, int> arr[100009];
int p[100009];
int main() {
  fact[0] = fact[1] = 1;
  for (int i = 2; i < 100009; i++) fact[i] = (fact[i - 1] * i) % mod;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    if (x != 0) arr[y].first = x, arr[y++].second = i;
    p[i] = x;
  }
  sort(arr, arr + y);
  if (y == n) {
    long long ans = 1;
    int l, r;
    l = r = arr[0].second;
    for (int i = 1; i < n; i++) {
      if (arr[i].second == r + 1)
        r++;
      else if (arr[i].second == l - 1)
        l--;
      else {
        ans = 0;
        break;
      }
    }
    printf("%lld\n", ans);
  } else
    printf("%lld\n", fn());
  return 0;
}
long long fn() {
  long long ret = 1;
  if (y == 0) return gn(n);
  if (arr[0].first == 1) {
    int r = arr[0].second, l = arr[0].second;
    for (int i = 1; i < y; i++) {
      int is_r = (arr[i].second >= r ? 1 : 0);
      int gap = is_r == 1 ? arr[i].second - r - 1 : l - arr[i].second - 1;
      int num_left = arr[i].first - arr[i - 1].first - 1;
      ret = ret * comb(num_left, gap), ret %= mod;
      ;
      r = is_r == 1 ? arr[i].second : r + (num_left - gap);
      l = is_r == 1 ? l - (num_left - gap) : arr[i].second;
    }
    if (arr[y - 1].first != n)
      ret = ret * comb(n - arr[y - 1].first, l), ret %= mod;
    ;
  } else {
    long long ans[2] = {0};
    for (int k = 0; k < 2; k++) {
      int r = arr[0].second, l = arr[0].second, prev = arr[0].first;
      int c = 0;
      if (k == 0)
        r = arr[0].first + arr[0].second - 1, l = arr[0].second,
        c = check(l + 1, r + 1);
      else
        l = arr[0].second - arr[0].first + 1, r = arr[0].second,
        c = check(l, r);
      if (l >= 0 && r <= n && c) {
        ans[k] = 1;
        for (int i = 1; i < y; i++) {
          if (arr[i].second >= r) {
            int gap = arr[i].second - r - 1;
            int num_left = arr[i].first - prev - 1;
            ans[k] = ans[k] * comb(num_left, gap), ans[k] %= mod;
            ;
            r = arr[i].second;
            l = l - (num_left - gap);
          } else {
            int gap = l - arr[i].second - 1;
            int num_left = arr[i].first - prev - 1;
            ans[k] = ans[k] * comb(num_left, gap), ans[k] %= mod;
            ;
            l = arr[i].second;
            r = r + (num_left - gap);
          }
          prev = arr[i].first;
        }
        if (arr[y - 1].first != n)
          ans[k] = ans[k] * comb(n - arr[y - 1].first, l), ans[k] %= mod;
        ;
        ans[k] *= gn(arr[0].first - 1), ans[k] %= mod;
      }
    }
    ret = ans[0] + ans[1], ret %= mod;
  }
  return ret;
}
int check(int start, int e) {
  for (int i = start; i < e; i++)
    if (p[i] != 0) return 0;
  return 1;
}
long long gn(int x) {
  if (x == 0) return 1;
  long long ret = 0;
  for (int i = 0; i < x; i++) ret += comb(x - 1, i), ret %= mod;
  return ret;
}
long long powr(long long x, long long y, long long mod) {
  long long ret = 1;
  while (y) {
    if (y & 1) ret = ret * x, ret %= mod;
    y >>= 1;
    x = (x * x) % mod;
  }
  return ret;
}
long long comb(int n, int c) {
  if (c == 0 || n == 0) return 1;
  if (c == 1) return n;
  long long num = fact[n];
  long long denom = (fact[c] * fact[n - c]) % mod;
  denom = powr(denom, mod - 2, mod);
  return (num * denom) % mod;
}
