#include <bits/stdc++.h>
using namespace std;
long long fact[100000 + 10], invf[100000 + 10];
long long fastpow(int a, int p) {
  long long ret = 1, t = a;
  while (p) {
    if (p & 1) ret = (ret * t) % 1000000007;
    t = (t * t) % 1000000007;
    p >>= 1;
  }
  return ret;
}
long long rev(int a) { return fastpow(a, 1000000007 - 2); }
void init() {
  fact[0] = 1;
  invf[0] = 1;
  for (int i = 1; i <= 100000; i++) {
    fact[i] = (fact[i - 1] * i) % 1000000007;
    invf[i] = rev(fact[i]);
  }
}
long long C(int a, int b) {
  if (a < 0 || b < 0) return 0;
  if (a > b) return 0;
  return ((fact[b] * invf[a]) % 1000000007 * invf[b - a]) % 1000000007;
}
int n, m;
long long tmp;
int ltmp, rtmp;
map<int, int> pos;
map<int, int>::iterator it;
int calc(int st, int mid) {
  int l = mid, r = mid, last = 1;
  long long ret = 1;
  int flag = 1;
  it = pos.begin();
  if (st == 2) it++;
  for (; it != pos.end(); ++it) {
    int i = it->first, p = it->second;
    if (l <= p && p <= r) {
      ret = tmp = 0;
      break;
    }
    if (l > pos[i]) {
      int empty = i - last - 1, need = l - p - 1;
      if (need > empty) {
        ret = tmp = 0;
        break;
      }
      l = p, r = p + i - 1;
      ret = (ret * C(need, empty)) % 1000000007;
      if (!flag) {
        tmp = (tmp * C(need, empty)) % 1000000007;
      } else {
        flag = 0;
        if (ltmp == l && rtmp == r) {
          return (ret * tmp) % 1000000007;
        } else {
          ltmp = l, rtmp = r;
          tmp = 1;
        }
      }
    } else {
      int empty = i - last - 1, need = p - r - 1;
      if (need > empty) {
        ret = tmp = 0;
        break;
      }
      r = p, l = p - i + 1;
      ret = (ret * C(need, empty)) % 1000000007;
      if (!flag) {
        tmp = (tmp * C(need, empty)) % 1000000007;
      } else {
        flag = 0;
        if (ltmp == l && rtmp == r) {
          return (ret * tmp) % 1000000007;
        } else {
          ltmp = l, rtmp = r;
          tmp = 1;
        }
      }
    }
    last = i;
  }
  return ret;
}
int main() {
  init();
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    if (x) pos[x] = i;
  }
  n++;
  pos[n] = n;
  if (pos.count(1))
    printf("%d\n", calc(2, pos[1]));
  else {
    int ans = 0;
    for (int i = 1; i <= n - 1; i++) ans = (ans + calc(1, i)) % 1000000007;
    printf("%d\n", ans);
  }
  return 0;
}
