#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int A[N], T[N];
int st[N << 2], tp[N << 2], lazy[N << 2];
void build(int in, int la, int ra) {
  lazy[in] = 0;
  if (la == ra) {
    st[in] = T[la];
    tp[in] = T[la] - la;
    return;
  }
  int mid = (la + ra) >> 1;
  int lt = (in << 1) + 1;
  int rt = lt + 1;
  build(lt, la, mid);
  build(rt, mid + 1, ra);
  st[in] = min(st[lt], st[rt]);
  tp[in] = min(tp[lt], tp[rt]);
}
void updateLazy(int in, int la, int ra) {
  if (la != ra) {
    int lt = (in << 1) + 1;
    int rt = lt + 1;
    lazy[lt] += lazy[in];
    lazy[rt] += lazy[in];
  }
  st[in] += lazy[in];
  tp[in] += lazy[in];
  lazy[in] = 0;
}
void update(int in, int la, int ra, int l, int r, int v) {
  if (lazy[in]) updateLazy(in, la, ra);
  if (ra < l || r < la || l > r) return;
  if (l <= la && ra <= r) {
    lazy[in] = v;
    updateLazy(in, la, ra);
    return;
  }
  int mid = (la + ra) >> 1;
  int lt = (in << 1) + 1;
  int rt = lt + 1;
  update(lt, la, mid, l, r, v);
  update(rt, mid + 1, ra, l, r, v);
  st[in] = min(st[lt], st[rt]);
  tp[in] = min(tp[lt], tp[rt]);
}
int get(int in, int la, int ra, int l, int r) {
  if (lazy[in]) updateLazy(in, la, ra);
  if (ra < l || r < la || l > r) return (N << 1);
  if (l <= la && ra <= r) return st[in];
  int mid = (la + ra) >> 1;
  int lt = (in << 1) + 1;
  int rt = lt + 1;
  return min(get(lt, la, mid, l, r), get(rt, mid + 1, ra, l, r));
}
int get_left(int in, int la, int ra) {
  if (lazy[in]) updateLazy(in, la, ra);
  if (tp[in] >= 0) return -1;
  if (la == ra) return la;
  int mid = (la + ra) >> 1;
  int lt = (in << 1) + 1;
  int rt = lt + 1;
  int ans = get_left(lt, la, mid);
  if (ans == -1) ans = get_left(rt, mid + 1, ra);
  return ans;
}
bool solve(int n, int t) {
  for (int i = 1; i <= n; i++) {
    T[i] = A[i] + i - 1;
  }
  build(0, 1, n);
  for (int i = 1; i <= n; i++) {
    int p = get_left(0, 1, n);
    if (p != -1) {
      p = min(t, p - 1);
      int l = get(0, 1, n, 1, p);
      if (l <= t) {
        int r = get(0, 1, n, p + 1, n);
        if (r <= t) return true;
      }
    }
    update(0, 1, n, 1, i, 1);
    update(0, 1, n, i + 1, n, -1);
  }
  return false;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
  }
  int l = 1, r = (N << 1);
  while (l < r) {
    int mid = (l + r) >> 1;
    if (solve(n, mid))
      r = mid;
    else
      l = mid + 1;
  }
  if (l == (N << 1)) {
    cout << "-1\n";
  } else {
    cout << l << "\n";
  }
  return 0;
}
