#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const long long inf = 1e9 + 7;
const long long max_n = 1e5 + 3, log_n = 20;
long long n;
long long a[max_n];
void solve() {
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long res = inf;
  vector<vector<long long>> sp_l(n, vector<long long>(log_n)),
      sp_r(n, vector<long long>(log_n));
  for (long long i = 0; i < n; i++)
    sp_l[i][0] = a[i] - i, sp_r[i][0] = a[i] + i;
  for (long long k = 1; k < log_n; k++) {
    for (long long i = 0; i + (1 << k) < n; i++) {
      sp_l[i][k] = min(sp_l[i][k - 1], sp_l[i + (1 << (k - 1))][k - 1]);
      sp_r[i][k] = min(sp_r[i][k - 1], sp_r[i + (1 << (k - 1))][k - 1]);
    }
  }
  function<long long(long long, long long)> g1 = [&sp_l](long long l,
                                                         long long r) {
    if (l > r) return inf;
    long long ln = 0;
    while ((1 << (ln + 1)) < r - l + 1) ln++;
    if (ln == 0) return sp_l[l][0];
    return min(sp_l[l][ln], sp_l[r - (1 << ln) + 1][ln]);
  };
  function<long long(long long, long long)> g2 = [&sp_r](long long l,
                                                         long long r) {
    if (l > r) return inf;
    long long ln = 0;
    while ((1 << (ln + 1)) < r - l + 1) ln++;
    if (ln == 0) return sp_r[l][0];
    return min(sp_r[l][ln], sp_r[r - (1 << ln) + 1][ln]);
  };
  function<long long(long long)> f1 = [](long long v) { return a[v] - 2 * v; };
  function<long long(long long)> f2 = [](long long v) { return a[v]; };
  function<long long(long long)> f3 = [](long long v) { return a[v] - v; };
  function<long long(long long)> f4 = [](long long v) { return a[v] + v; };
  auto cmp1 = [f1](long long v1, long long v2) {
    if (f1(v1) == f1(v2)) return v1 < v2;
    return f1(v1) > f1(v2);
  };
  auto cmp2 = [f2](long long v1, long long v2) {
    if (f2(v1) == f2(v2)) return v1 < v2;
    return f2(v1) < f2(v2);
  };
  auto cmp3 = [f3](long long v1, long long v2) {
    if (f3(v1) == f3(v2)) return v1 < v2;
    return f3(v1) < f3(v2);
  };
  auto cmp4 = [f4](long long v1, long long v2) {
    if (f4(v1) == f4(v2)) return v1 < v2;
    return f4(v1) < f4(v2);
  };
  set<long long, decltype(cmp1)> t_l(cmp1);
  set<long long, decltype(cmp2)> t_r(cmp2);
  set<long long, decltype(cmp3)> s_l(cmp3);
  set<long long, decltype(cmp4)> s_r(cmp4);
  set<long long> t_all;
  for (long long i = 0; i < n; i++) {
    if (f2(i) > 0)
      t_r.emplace(i);
    else
      t_all.emplace(i), s_r.emplace(i);
  }
  for (long long t = 0; t < n; t++) {
    while ((long long)(t_r.size()) && f2(*t_r.begin()) - t <= 0) {
      if ((*t_r.begin()) > t)
        t_all.emplace(*t_r.begin()), s_r.emplace(*t_r.begin());
      t_r.erase(t_r.begin());
    }
    while ((long long)(t_l.size()) && f1(*t_l.begin()) + t > 0) {
      t_all.erase(*t_l.begin());
      s_l.erase(*t_l.begin());
      t_l.erase(t_l.begin());
    }
    if (a[t] <= t) {
      s_l.emplace(t);
      s_r.erase(t);
      t_l.emplace(t);
      t_all.emplace(t);
    }
    long long nres = inf;
    if ((long long)(s_l.size())) nres = f3(*s_l.begin()) + t;
    if ((long long)(s_r.size())) nres = min(nres, f4(*s_r.begin()) - t);
    long long ri = ((long long)(t_all.size()) ? (*t_all.begin()) : n);
    long long r1 = g1(0, min(t - 1, ri - 1)) + t;
    r1 = min(r1, g2(t, ri - 1) - t);
    res = min(res, max(r1, nres));
  }
  cout << (res == inf ? -1 : res) << endl;
}
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  cout.precision(10);
  solve();
}
