#include <bits/stdc++.h>
using namespace std;
const int N = 105000, M = 350;
mt19937 gen(time(NULL));
template <typename T = int>
inline T read() {
  T val = 0, sign = 1;
  char ch;
  for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') sign = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) val = val * 10 + ch - '0';
  return sign * val;
}
long long a[N], falls[N];
struct spt {
  vector<vector<long long>> dp;
  vector<int> log;
  int n;
  bool isMax;
  void init(vector<int> a) {
    for (int i = 1; i <= n; i++) dp[0][i] = a[i];
    for (int k = 1; (1 << k) <= n; k++)
      for (int i = 1; i + (1 << k) <= n + 1; i++) {
        long long lval = dp[k - 1][i], rval = dp[k - 1][i + (1 << (k - 1))];
        if (isMax)
          dp[k][i] = max(lval, rval);
        else
          dp[k][i] = min(lval, rval);
      }
  }
  long long get(int l, int r) {
    if (l > r) assert(0);
    int k = log[r - l + 1];
    long long lval = dp[k][l], rval = dp[k][r - (1 << k) + 1];
    return isMax ? max(lval, rval) : min(lval, rval);
  }
  spt(int n, bool isMax = true) : n(n), isMax(isMax) {
    log.resize(n + 1);
    for (int i = 2; i <= n; i++) log[i] = log[i / 2] + 1;
    dp.resize(20);
    for (int i = 0; i < 20; i++) {
      dp[i].resize(n + 1);
      if (!isMax) fill((dp[i]).begin(), (dp[i]).end(), 1e18);
    }
  }
};
long long lm[N], rm[N];
int ws1[N], n;
void solve() {
  n = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  long long ans = 1e18;
  int L = 1, R = 1;
  fill_n(lm, N, 1e18), fill_n(rm, N, 1e18);
  for (int i = 1; i <= n; i++) ws1[i] = 2 * i - a[i];
  auto S = spt(n, false);
  S.init(vector<int>(a, a + n + 1));
  auto LS = spt(n, false);
  vector<int> la(n + 1);
  for (int i = 1; i <= n; i++) la[i] = a[i] - i;
  LS.init(la);
  auto RS = spt(n, false);
  for (int i = 1; i <= n; i++) la[i] = a[i] + i;
  RS.init(la);
  for (int T = 1; T <= n; T++) {
    while (L <= T && T >= 2 * L - a[L]) L++;
    int j = -1;
    if (L <= T)
      j = L;
    else {
      int lx = T, rx = n;
      int ind_ans = -1;
      while (lx <= rx) {
        int mx = (lx + rx) / 2;
        if (S.get(T, mx) >= T) {
          lx = mx + 1;
        } else {
          ind_ans = mx;
          rx = mx - 1;
        }
      }
      if (ind_ans == -1) continue;
      j = ind_ans;
    }
    long long lp = 0, rp = 0;
    fprintf(stderr, "[%d -> %d]\n", T, j), fflush(stderr);
    if (j <= T) {
      lp = LS.get(1, j - 1) + T;
      rp = min(LS.get(j, T) + T, RS.get(T, n) - T);
    } else {
      lp = min(LS.get(1, T) + T, RS.get(T, j - 1) - T);
      rp = RS.get(j, n) - T;
    }
    fprintf(stderr, "%lld %lld\n", lp, rp), fflush(stderr);
    ans = min(ans, max(lp, rp));
  }
  if (ans == 1e18)
    puts("-1");
  else
    printf("%lld\n", ans);
}
void precalc() {}
signed main() {
  int t = 1;
  precalc();
  while (t--) {
    clock_t z = clock();
    solve();
    fprintf(stderr, "Total Time: %.3f\n",
            (double)(clock() - z) / CLOCKS_PER_SEC),
        fflush(stderr);
  }
}
