#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 9;
const long long INF = 1e9;
long long n;
long long a[N];
long long prep[2][N];
pair<long long, long long> t[2][8 * N];
long long pushing[2][8 * N];
void build(long long z, long long v, long long tl, long long tr) {
  if (tl == tr) {
    t[z][v] = make_pair(prep[z][tl], tl);
    return;
  }
  long long tm = (tl + tr) >> 1;
  build(z, v << 1, tl, tm);
  build(z, v << 1 | 1, tm + 1, tr);
  t[z][v] = min(t[z][v << 1], t[z][v << 1 | 1]);
}
void push(long long z, long long v) {
  if (pushing[z][v] == 0) return;
  t[z][v << 1].first += pushing[z][v];
  t[z][v << 1 | 1].first += pushing[z][v];
  pushing[z][v << 1] += pushing[z][v];
  pushing[z][v << 1 | 1] += pushing[z][v];
  pushing[z][v] = 0;
}
pair<long long, long long> get(long long z, long long v, long long tl,
                               long long tr, long long l, long long r) {
  if (l > r) return make_pair(INF, INF);
  push(z, v);
  if (tl == l && tr == r) {
    return t[z][v];
  }
  long long tm = (tl + tr) >> 1;
  return min(get(z, v << 1, tl, tm, l, min(r, tm)),
             get(z, v << 1 | 1, tm + 1, tr, max(l, tm + 1), r));
}
pair<long long, long long> get_super(long long v, long long tl, long long tr,
                                     long long l, long long r) {
  if (l > r) return make_pair(INF, INF);
  push(1, v);
  if (tl == l && tr == r) {
    if (tl == tr) return t[1][v];
    long long tm = (tl + tr) >> 1;
    if (t[1][v << 1].first <= 0)
      return get_super(v << 1, tl, tm, l, min(r, tm));
    else
      return get_super(v << 1 | 1, tm + 1, tr, max(tm + 1, l), r);
  }
  long long tm = (tl + tr) >> 1;
  pair<long long, long long> lf = get_super(v << 1, tl, tm, l, min(r, tm));
  pair<long long, long long> rf =
      get_super(v << 1 | 1, tm + 1, tr, max(l, tm + 1), r);
  if (lf.first <= 0) return lf;
  return rf;
}
void upd(long long z, long long v, long long tl, long long tr, long long l,
         long long r, long long add) {
  if (l > r) return;
  push(z, v);
  if (tl == l && tr == r) {
    t[z][v].first += add;
    pushing[z][v] = add;
    push(z, v);
    return;
  }
  long long tm = (tl + tr) >> 1;
  upd(z, v << 1, tl, tm, l, min(tm, r), add);
  upd(z, v << 1 | 1, tm + 1, tr, max(tm + 1, l), r, add);
  t[z][v] = min(t[z][v << 1], t[z][v << 1 | 1]);
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
    prep[0][i] = a[i] + i;
    prep[1][i] = a[i];
  }
  build(0, 1, 0, n - 1);
  build(1, 1, 0, n - 1);
  long long ans = -1;
  for (long long i = 0; i < n; ++i) {
    long long l = 0;
    long long r = n - 1;
    long long j, tim;
    if (get(1, 1, 0, n - 1, 0, n - 1).first > 0) goto fin;
    while (l < r) {
      long long m = (l + r) >> 1;
      if (get(1, 1, 0, n - 1, 0, m).first <= 0)
        r = m;
      else
        l = min(n - 1, m + 1);
      if (l == r - 1) {
        if (get(1, 1, 0, n - 1, 0, l).first <= 0)
          r = l;
        else
          l = r;
      }
    }
    j = r;
    tim =
        max(get(0, 1, 0, n - 1, 0, j - 1), get(0, 1, 0, n - 1, j, n - 1)).first;
    if (ans == -1) ans = tim;
    ans = min(ans, tim);
  fin:
    for (long long z : {0, 1}) {
      upd(z, 1, 0, n - 1, 0, i, +1);
      upd(z, 1, 0, n - 1, i + 1, n - 1, -1);
    }
  }
  cout << ans << endl;
}
