#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long linf = 1ll * inf * inf;
const int N = 300000 + 7;
const int M = 19;
const int multipleTest = 0;
struct RMQ {
  int a[N];
  int RMQ[N][20];
  int n;
  int& operator[](int pos) { return a[pos]; }
  void build() {
    for (int i = (1), _b = (n + 1); i < _b; ++i) {
      RMQ[i][0] = a[i];
    }
    for (int j = (1), _b = (20); j < _b; ++j) {
      int lt = 1 << j;
      int half = lt >> 1;
      for (int i = 1; i + lt - 1 <= n; ++i) {
        RMQ[i][j] = min(RMQ[i][j - 1], RMQ[i + half][j - 1]);
      }
    }
  }
  int get(int u, int v) {
    int k = log2(v - u + 1);
    return min(RMQ[u][k], RMQ[v - (1 << k) + 1][k]);
  }
} rmq1, rmq2, rmq3;
int n;
int a[N];
int mx_left[N];
int get_left(int r) {
  int lo = 1, hi = r - 1, res = -1;
  while (lo <= hi) {
    int g = (lo + hi) >> 1;
    if (mx_left[g] > r) {
      res = g;
      hi = g - 1;
    } else
      lo = g + 1;
  }
  return res;
}
int get_right(int r) {
  int lo = r, hi = n, res = -1;
  while (lo <= hi) {
    int g = (lo + hi) >> 1;
    if (rmq1.get(r, g) < r) {
      res = g;
      hi = g - 1;
    } else
      lo = g + 1;
  }
  return res;
}
int calc(int r) {
  int j = get_left(r);
  if (j == -1) j = get_right(r);
  if (j == -1) return inf;
  int rhs = inf;
  if (j <= n) rhs = min(rhs, rmq2.get(max(r, j), n) - r);
  if (j < r) rhs = min(rhs, rmq3.get(j, r - 1) + r);
  int lhs = inf;
  --j;
  if (j > 0) {
    lhs = min(lhs, rmq3.get(1, min(j, r - 1)) + r);
    if (j >= r) lhs = min(lhs, rmq2.get(r, j) - r);
  }
  return max(lhs, rhs);
}
void solve() {
  cin >> n;
  rmq1.n = rmq2.n = rmq3.n = n;
  for (int i = (1), _b = (n + 1); i < _b; ++i) {
    scanf("%d", a + i);
    rmq1[i] = a[i];
    rmq2[i] = a[i] + i;
    rmq3[i] = -i + a[i];
    mx_left[i] = max(mx_left[i - 1], 2 * i - a[i]);
  }
  rmq1.build();
  rmq2.build();
  rmq3.build();
  int res = inf;
  for (int i = (1), _b = (n + 1); i < _b; ++i) res = min(res, calc(i));
  if (res >= inf) res = -1;
  cout << res;
}
int main() {
  int Test = 1;
  if (multipleTest) {
    cin >> Test;
  }
  for (int i = 0; i < Test; ++i) {
    solve();
  }
}
