#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 17;
const int INF = 1e8;
int T[2 * N];
int lazy[2 * N];
int A[N];
void updateR(int l, int r, int v, int node = 1, int nl = 1, int nr = N) {
  if (lazy[node] != 0) {
    T[node] += lazy[node];
    if (nl != nr)
      lazy[2 * node] += lazy[node], lazy[2 * node + 1] += lazy[node];
    lazy[node] = 0;
  }
  if ((l <= nl) && (nr <= r)) {
    T[node] += v;
    if (nl != nr) lazy[2 * node] += v, lazy[2 * node + 1] += v;
    return;
  }
  if ((nl > r) || (l > nr)) return;
  int m = (nl + nr) / 2;
  updateR(l, r, v, 2 * node, nl, m);
  updateR(l, r, v, 2 * node + 1, m + 1, nr);
  T[node] = min(T[2 * node], T[2 * node + 1]);
  lazy[node] = 0;
}
int query(int l, int r, int node = 1, int nl = 1, int nr = N) {
  if ((nl > r) || (l > nr)) return INF;
  if (lazy[node] != 0) {
    T[node] += lazy[node];
    if (nl != nr)
      lazy[2 * node] += lazy[node], lazy[2 * node + 1] += lazy[node];
    lazy[node] = 0;
  }
  if ((l <= nl) && (nr <= r)) return T[node];
  int m = (nl + nr) / 2;
  int p = query(l, r, 2 * node, nl, m);
  int q = query(l, r, 2 * node + 1, m + 1, nr);
  return min(p, q);
}
vector<pair<bool, int>> evs[N];
int main() {
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> A[i];
  for (int i = 1; i <= n; i++) {
    T[N + i - 1] = A[i] + i - 1;
    if (A[i] + 1 <= i) {
      evs[A[i] + 1].push_back({1, i});
      if (2 * i - A[i] <= n) evs[2 * i - A[i]].push_back({0, i});
    }
  }
  for (int i = n; i < N; i++) T[N + i] = INF;
  for (int j = N / 2; j >= 1; j /= 2)
    for (int i = j; i < 2 * j; i++) T[i] = min(T[2 * i], T[2 * i + 1]);
  int ans = INF;
  set<int> falls;
  for (int t = 1; t <= n; t++) {
    if (t > 1) {
      updateR(1, t - 1, +1);
      updateR(t, n, -1);
    }
    for (pair<int, int> p : evs[t]) {
      if (p.first)
        falls.insert(p.second);
      else
        falls.erase(p.second);
    }
    if (falls.size()) {
      int j = *falls.begin();
      ans = min(ans, max(query(1, j - 1), query(j, n)));
    }
  }
  if (ans == INF) ans = -1;
  cout << ans << endl;
  return 0;
}
