#include <bits/stdc++.h>
using namespace std;
inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline int read() {
  int x = 0;
  char ch = getchar();
  bool positive = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') positive = 0;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return positive ? x : -x;
}
inline void write(int a) {
  if (a >= 10) write(a / 10);
  putchar('0' + a % 10);
}
inline void writeln(int a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  write(a);
  puts("");
}
const int N = 100005;
const int nn = 1e5, inf = 2e9;
int n, a[N], tree[N << 2], v[N];
struct data {
  pair<int, int> tree[N << 2];
  multiset<pair<int, int> > s[N];
  void init() {
    for (int i = 1; i < (N << 2); i++) tree[i] = make_pair(inf, inf);
    for (int i = 1; i <= nn; i++) s[i].insert(make_pair(inf, inf));
  }
  void insert(int l, int r, int pos, int de, int id, int nod) {
    if (pos > r) return;
    if (l == r) {
      if (id > 0)
        s[l].insert(make_pair(de, id));
      else
        s[l].erase(make_pair(de, -id));
      tree[nod] = *s[l].begin();
      return;
    }
    int mid = (l + r) >> 1;
    if (pos <= mid)
      insert(l, mid, pos, de, id, nod << 1);
    else
      insert(mid + 1, r, pos, de, id, nod << 1 | 1);
    tree[nod] = min(tree[nod << 1], tree[nod << 1 | 1]);
  }
  pair<int, int> ask(int l, int r, int i, int j, int nod) {
    if (i > j) return make_pair(inf, inf);
    if (l == i && r == j) return tree[nod];
    int mid = (l + r) >> 1;
    if (j <= mid)
      return ask(l, mid, i, j, nod << 1);
    else if (i > mid)
      return ask(mid + 1, r, i, j, nod << 1 | 1);
    else
      return min(ask(l, mid, i, mid, nod << 1),
                 ask(mid + 1, r, mid + 1, j, nod << 1 | 1));
  }
} T[2];
int main() {
  n = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  for (int i = 0; i < 2; i++) T[i].init();
  for (int i = 1; i <= n; i++) {
    T[0].insert(1, nn, a[i], a[i] + i, i, 1);
  }
  int ans = inf;
  pair<int, int> t1, t2;
  for (int i = 1; i <= n; i++) {
    t2 = T[0].ask(1, nn, 1, i - 1, 1);
    t1 = T[1].ask(1, nn, 1, i, 1);
    if (t1.second < t2.second) ans = min(ans, max(t1.first + i, t2.first - i));
    t1 = T[1].ask(1, nn, 1, i, 1);
    t2 = T[1].ask(1, nn, i + 1, nn, 1);
    if (t1.second < t2.second) ans = min(ans, max(t1.first + i, t2.first + i));
    t1 = T[0].ask(1, nn, i, nn, 1);
    t2 = T[0].ask(1, nn, 1, i - 1, 1);
    if (t1.second < t2.second) ans = min(ans, max(t1.first - i, t2.first - i));
    T[1].insert(1, nn, max(2 * i - a[i], 1), a[i] - i, i, 1);
    T[0].insert(1, nn, a[i], a[i] + i, -i, 1);
  }
  writeln(ans > 100000000 ? -1 : ans);
}
