#include <bits/stdc++.h>
int a[262144];
int stl[262144 << 1], str[262144 << 1];
int stn[262144 << 1], stp[262144 << 1];
void build(int *st, int x, int n) {
  int c = __builtin_clz(x);
  int l = (x ^ 1u << 31 >> c) << c - __builtin_clz(262144);
  if (l >= n) {
    st[x] = ((int)1e9);
    return;
  }
  if (x >= 262144) return;
  build(st, x << 1, n);
  build(st, x << 1 | 1, n);
  st[x] = std::min(st[x << 1], st[x << 1 | 1]);
}
int search(int *st, int x, int ql, int qr, int k) {
  int c = __builtin_clz(x);
  int l = (x ^ 1u << 31 >> c) << c - __builtin_clz(262144),
      r = l + (1u << c - __builtin_clz(262144));
  if (qr <= l || r <= ql) return -1;
  if (st[x] > k) return -1;
  if (r - l == 1) return st[x] <= k ? l : -1;
  int ans = search(st, x << 1, ql, qr, k);
  if (ans == -1) ans = search(st, x << 1 | 1, ql, qr, k);
  return ans;
}
int min(int *st, int x, int ql, int qr) {
  int c = __builtin_clz(x);
  int l = (x ^ 1u << 31 >> c) << c - __builtin_clz(262144),
      r = l + (1u << c - __builtin_clz(262144));
  if (qr <= l || r <= ql) return ((int)1e9);
  if (ql <= l && r <= qr) return st[x];
  return std::min(min(st, x << 1, ql, qr), min(st, x << 1 | 1, ql, qr));
}
int main() {
  int n;
  int ans = ((int)1e9);
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", a + i);
  for (int i = 0; i < n; ++i) stl[i | 262144] = a[i] - i * 2;
  for (int i = 0; i < n; ++i) str[i | 262144] = a[i];
  for (int i = 0; i < n; ++i) stn[i | 262144] = a[i] - i;
  for (int i = 0; i < n; ++i) stp[i | 262144] = a[i] + i;
  build(stl, 1, n);
  build(str, 1, n);
  build(stn, 1, n);
  build(stp, 1, n);
  for (int i = 0; i < n; ++i) {
    int tl, tr, p = search(stl, 1, 0, i, -i);
    if (p == -1) p = search(str, 1, i, n, i);
    if (p == -1) continue;
    tl = std::min(min(stn, 1, 0, std::min(p, i)) + i, min(stp, 1, i, p) - i);
    tr = std::min(min(stn, 1, p, i) + i, min(stp, 1, std::max(p, i), n) - i);
    0;
    ans = std::min(ans, std::max(tl, tr));
  }
  printf("%d\n", ans == ((int)1e9) ? -1 : ans);
  return 0;
}
