#include <bits/stdc++.h>
using namespace std;
double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};
int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1};
inline string IntToString(long long a) {
  char x[100];
  sprintf(x, "%lld", a);
  string s = x;
  return s;
}
inline long long StringToInt(string a) {
  char x[100];
  long long res;
  strcpy(x, a.c_str());
  sscanf(x, "%lld", &res);
  return res;
}
inline string GetString(void) {
  char x[1000005];
  scanf("%s", x);
  string s = x;
  return s;
}
inline string uppercase(string s) {
  int n = (int)s.size();
  for (int(i) = (0); (i) < (n); ++(i))
    if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}
inline string lowercase(string s) {
  int n = (int)s.size();
  for (int(i) = (0); (i) < (n); ++(i))
    if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}
inline void OPEN(string s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}
int T, n, x;
int pos[100005];
int posr[100005];
long long MOD = 1000000007;
long long f[100005];
vector<pair<int, int> > angka;
long long bigmod(int a, int b, int MOD) {
  long long x = 1, y = a;
  while (b > 0) {
    if (b % 2 == 1) x = (x * y) % MOD;
    y = (y * y) % MOD;
    b /= 2;
  }
  return x;
}
long long inverse(int n, int M) { return bigmod(n, M - 2, M); }
long long C(int n, int r) {
  if (n < r) return 0;
  return (f[n] * ((inverse(f[r], MOD) * inverse(f[n - r], MOD)) % MOD)) % MOD;
}
int main() {
  f[0] = 1;
  for (int(i) = (1); (i) <= (100000); ++(i)) {
    f[i] = (f[i - 1] * i) % MOD;
  }
  T = 1;
  while (T--) {
    pair<int, int> kecil2 = make_pair(INF, INF);
    angka.clear();
    scanf("%d", &n);
    memset(pos, -1, sizeof(pos));
    memset(posr, -1, sizeof(posr));
    for (int(i) = (0); (i) < (n); ++(i)) {
      scanf("%d", &x);
      if (x > 0) {
        pos[x - 1] = i;
        posr[i] = x - 1;
        kecil2 = min(kecil2, make_pair(x - 1, i));
        if (x - 1 > 0) angka.push_back(make_pair(x - 1, i));
      }
    }
    int kecil = kecil2.second;
    if (kecil == INF) {
      long long risan = 1;
      for (int(i) = (0); (i) < (n - 1); ++(i)) risan = (risan * 2LL) % MOD;
      printf("%lld\n", risan);
      continue;
    }
    angka.push_back(make_pair(n, n));
    sort(angka.begin(), angka.end());
    long long risan = 0;
    long long petrus1 = 1;
    long long petrus2 = 1;
    if (kecil2.first != 0) {
      int R = angka[0].second + 1;
      int L = angka[0].second - angka[0].first - 1;
      if (-1 <= L && R <= n) {
        int last = angka[0].first;
        for (int(j) = (1); (j) < ((int)angka.size()); ++(j)) {
          if (L < angka[j].second && angka[j].second < R) {
            petrus1 = 0;
            break;
          }
          int ada = angka[j].first - last;
          if (R <= angka[j].second) {
            int sisa = angka[j].second - R;
            if (ada < sisa) {
              petrus1 = 0;
              break;
            }
            petrus1 = (petrus1 * C(ada - 1, sisa)) % MOD;
            L -= (ada - sisa - 1);
            R = angka[j].second + 1;
          } else if (angka[j].second <= L) {
            int sisa = L - angka[j].second;
            if (ada < sisa) {
              petrus1 = 0;
              break;
            }
            petrus1 = (petrus1 * C(ada - 1, sisa)) % MOD;
            R += (ada - sisa - 1);
            L = angka[j].second - 1;
          }
          last = angka[j].first;
        }
      } else
        petrus1 = 0;
    }
    if (kecil2.first != 0) {
      int L = angka[0].second - 1;
      int R = angka[0].second + angka[0].first + 1;
      if (-1 <= L && R <= n) {
        int last = angka[0].first;
        for (int(j) = (1); (j) < ((int)angka.size()); ++(j)) {
          if (L < angka[j].second && angka[j].second < R) {
            petrus2 = 0;
            break;
          }
          int ada = angka[j].first - last;
          if (R <= angka[j].second) {
            int sisa = angka[j].second - R;
            if (ada < sisa) {
              petrus2 = 0;
              break;
            }
            petrus2 = (petrus2 * C(ada - 1, sisa)) % MOD;
            L -= (ada - sisa - 1);
            R = angka[j].second + 1;
          } else if (angka[j].second <= L) {
            int sisa = L - angka[j].second;
            if (ada < sisa) {
              petrus2 = 0;
              break;
            }
            petrus2 = (petrus2 * C(ada - 1, sisa)) % MOD;
            R += (ada - sisa - 1);
            L = angka[j].second - 1;
          }
          last = angka[j].first;
        }
      } else
        petrus2 = 0;
    }
    for (int(i) = (0); (i) < (n); ++(i))
      if (pos[0] == -1 || pos[0] == i) {
        long long petrus = 1;
        int L = i - 1;
        int R = i + 1;
        int last = 0;
        for (int(j) = (0); (j) < ((int)angka.size()); ++(j)) {
          if (j == 1 && kecil2.first > 0) break;
          if (L < angka[j].second && angka[j].second < R) {
            petrus = 0;
            break;
          }
          int ada = angka[j].first - last;
          if (R <= angka[j].second) {
            int sisa = angka[j].second - R;
            if (ada < sisa) {
              petrus = 0;
              break;
            }
            petrus = (petrus * C(ada - 1, sisa)) % MOD;
            L -= (ada - sisa - 1);
            R = angka[j].second + 1;
          } else if (angka[j].second <= L) {
            int sisa = L - angka[j].second;
            if (ada < sisa) {
              petrus = 0;
              break;
            }
            petrus = (petrus * C(ada - 1, sisa)) % MOD;
            R += (ada - sisa - 1);
            L = angka[j].second - 1;
          }
          last = angka[j].first;
        }
        if (kecil2.first > 0) {
          if (i < kecil)
            petrus = (petrus * petrus1) % MOD;
          else
            petrus = (petrus * petrus2) % MOD;
        }
        risan += petrus;
        if (risan > MOD) risan -= MOD;
      }
    printf("%lld\n", risan);
  }
  return 0;
}
