#include <bits/stdc++.h>
using namespace std;
int const MAX = 100 * 1000 + 41;
int const INF = 1000 * 1000 * 1000 + 41;
int const REALANS = 1000 * 1000 * 100 + 41;
int n;
int a[MAX];
int ans;
struct Node {
  int x, v, p;
  Node(){};
  Node(int x, int v, int p) : x(x), v(v), p(p){};
  bool operator<(const Node &a) const { return x < a.x; };
};
struct Tree {
  int t[MAX * 4];
  vector<Node> a, b;
  int l, r, val, p;
  int pos[MAX];
  Tree(){};
  void build(int v, int tl, int tr) {
    if (tl == tr) {
      t[v] = INF;
    } else {
      int tm = (tl + tr) / 2;
      build(v * 2 + 1, tl, tm);
      build(v * 2 + 2, tm + 1, tr);
      t[v] = min(t[v * 2 + 1], t[v * 2 + 2]);
    }
  }
  void build(vector<Node> v) {
    a = v;
    b = v;
    sort(b.begin(), b.end());
    build(0, 1, n);
    for (int i = 0; i <= (int)b.size() - 1; i++) {
      pos[b[i].p] = i + 1;
    }
  }
  int ask(int v, int tl, int tr) {
    if (l > tr || tl > r) return INF;
    if (l <= tl && tr <= r) {
      return t[v];
    }
    int tm = (tl + tr) / 2;
    return min(ask(v * 2 + 1, tl, tm), ask(v * 2 + 2, tm + 1, tr));
  }
  int ask(int x) {
    int l = -1;
    int r = (int)b.size();
    while (r - l > 1) {
      int h = (l + r) / 2;
      if (b[h].x >= x) {
        r = h;
      } else {
        l = h;
      }
    }
    this->l = r + 1;
    this->r = n;
    return ask(0, 1, n);
  }
  void upd(int v, int tl, int tr) {
    if (tl == tr) {
      t[v] = val;
    } else {
      int tm = (tl + tr) / 2;
      if (p <= tm) {
        upd(v * 2 + 1, tl, tm);
      } else {
        upd(v * 2 + 2, tm + 1, tr);
      }
      t[v] = min(t[v * 2 + 1], t[v * 2 + 2]);
    }
  }
  void push(int i) {
    p = pos[i];
    val = a[i - 1].v;
    upd(0, 1, n);
  }
};
int l[MAX];
int r[MAX];
Tree l1, l2, r1, r2;
bool fl[MAX];
void buildl() {
  for (int i = 1; i <= n; i++) {
    l[i] = INF;
  }
  int cur = INF;
  for (int i = 1; i <= n; i++) {
    if (cur <= a[i] - i) {
      fl[i] = false;
    } else {
      fl[i] = true;
      cur = a[i] - i;
    }
  }
  for (int i = 1; i <= n; i++) {
    while (false) {
    };
  }
  vector<Node> v;
  v.clear();
  for (int i = 1; i <= n; i++) {
    v.push_back(Node(a[i] - i * 2, a[i] - i, i));
  }
  l1.build(v);
  for (int i = 1; i <= n; i++) {
    if (fl[i]) {
      l1.push(i);
    }
    l[i] = min(l[i], l1.ask(-i) + i);
  }
  v.clear();
  for (int i = 1; i <= n; i++) {
    v.push_back(Node(a[i], a[i] + i, i));
  }
  l2.build(v);
  for (int i = n; i >= 1; i--) {
    if (fl[i]) {
      l2.push(i);
    }
    l[i] = min(l[i], l2.ask(i) - i);
  }
}
void buildr() {
  for (int i = 1; i <= n; i++) {
    r[i] = INF;
  }
  vector<Node> v;
  v.clear();
  for (int i = 1; i <= n; i++) {
    v.push_back(Node(i * 2 - a[i], a[i] - i, i));
  }
  r1.build(v);
  for (int i = 1; i <= n; i++) {
    r1.push(i);
    r[i] = min(r[i], r1.ask(i + 1) + i);
  }
  v.clear();
  for (int i = 1; i <= n; i++) {
    v.push_back(Node(-a[i], a[i] + i, i));
  }
  r2.build(v);
  for (int i = n; i >= 1; i--) {
    r2.push(i);
    r[i] = min(r[i], r2.ask(-i + 1) - i);
  }
}
void solve() {
  buildl();
  buildr();
  ans = INF;
  for (int i = 1; i <= n; i++) {
    ans = min(ans, max(l[i], r[i]));
  }
  if (ans > REALANS) {
    ans = -1;
  }
  printf("%d\n", ans);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  solve();
  return 0;
}
