Andrew's favourite Krakozyabra has recenly fled away and now he's eager to bring it back!

At the moment the refugee is inside an icy cave with n icicles dangling from the ceiling located in integer coordinates numbered from 1 to n. The distance between floor and the i-th icicle is equal to ai.

Andrew is free to choose an arbitrary integer point T in range from 1 to n inclusive and at time instant 0 launch a sound wave spreading into both sides (left and right) at the speed of one point per second. Any icicle touched by the wave starts falling at the same speed (that means that in a second the distance from floor to icicle decreases by one but cannot become less that zero). While distance from icicle to floor is more than zero, it is considered passable; as soon as it becomes zero, the icicle blocks the path and prohibits passing.

Krakozyabra is initially (i.e. at time instant 0) is located at point <image> and starts running in the right direction at the speed of one point per second. You can assume that events in a single second happen in the following order: first Krakozyabra changes its position, and only then the sound spreads and icicles fall; in particular, that means that if Krakozyabra is currently at point <image> and the falling (i.e. already touched by the sound wave) icicle at point i is 1 point from the floor, then Krakozyabra will pass it and find itself at <image> and only after that the icicle will finally fall and block the path.

Krakozyabra is considered entrapped if there are fallen (i.e. with ai = 0) icicles both to the left and to the right of its current position. Help Andrew find the minimum possible time it takes to entrap Krakozyabra by choosing the optimal value of T or report that this mission is impossible.

Input

The first line contains the number of icicles n (2 ≤ n ≤ 105).

The next line contains n space-separated numbers ai (1 ≤ ai ≤ 105) — the distances from floor to icicles.

Output

Print an only integer — the minimum time it takes to entrap Krakozyabra between two fallen icicles. If it is impossible, print  - 1.

Examples

Input

5
1 4 3 5 1


Output

3


Input

4
1 2 1 1


Output

2


Input

2
2 1


Output

3


Input

2
1 2


Output

-1

Note

In sample case one it's optimal to launch the sound wave from point 3. Then in two seconds icicles 1 and 5 will start falling, and in one more seconds they will block the paths. Krakozyabra will be located at <image> at that time. Note that icicle number 3 will also be fallen, so there will actually be two icicles blocking the path to the left.

In sample case two it is optimal to launch the wave from point 2 and entrap Krakozyabra in 2 seconds.

In sample case four the answer is impossible.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100011;
int mn[maxn][20], mn1[maxn][20], mn2[maxn][20];
int n, a[maxn], ss[maxn], sss[maxn], Log2[maxn];
inline int Query(int a, int b) {
  if (a > b) return INT_MAX;
  int Len = Log2[b - a + 1];
  return min(mn[a][Len], mn[b - (1 << Len) + 1][Len]);
}
inline int Query1(int a, int b) {
  if (a > b) return INT_MAX;
  int Len = Log2[b - a + 1];
  return min(mn1[a][Len], mn1[b - (1 << Len) + 1][Len]);
}
inline int Query2(int a, int b) {
  if (a > b) return INT_MAX;
  int Len = Log2[b - a + 1];
  return min(mn2[a][Len], mn2[b - (1 << Len) + 1][Len]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  int rans = INT_MAX;
  Log2[1] = 0;
  for (int i = 2; i <= n; ++i) Log2[i] = Log2[i >> 1] + 1;
  for (int i = 1; i <= n; ++i) mn[i][0] = a[i];
  for (int i = n; i >= 1; --i)
    for (int j = 1; i + (1 << j) - 1 <= n; ++j)
      mn[i][j] = min(mn[i][j - 1], mn[i + (1 << (j - 1))][j - 1]);
  for (int i = 1; i <= n; ++i) mn1[i][0] = a[i] + i;
  for (int i = n; i >= 1; --i)
    for (int j = 1; i + (1 << j) - 1 <= n; ++j)
      mn1[i][j] = min(mn1[i][j - 1], mn1[i + (1 << (j - 1))][j - 1]);
  for (int i = 1; i <= n; ++i) mn2[i][0] = a[i] - i;
  for (int i = n; i >= 1; --i)
    for (int j = 1; i + (1 << j) - 1 <= n; ++j)
      mn2[i][j] = min(mn2[i][j - 1], mn2[i + (1 << (j - 1))][j - 1]);
  ss[0] = INT_MAX;
  for (int i = 1; i <= n; ++i) ss[i] = min(ss[i - 1], a[i] - 2 * i);
  sss[0] = INT_MAX;
  for (int i = 1; i <= n; ++i) sss[i] = min(sss[i - 1], a[i] - i);
  for (int w = 1; w <= n; ++w) {
    if (ss[w] >= -w) {
      int l = w + 1, r = n;
      while (l <= r) {
        int mid = (l + r) >> 1;
        if (Query(w + 1, mid) < w)
          r = mid - 1;
        else
          l = mid + 1;
      }
      int x = r + 1;
      if (x > n) continue;
      int ans =
          max(Query1(x, n) - w, min(Query1(w + 1, x - 1) - w, sss[w] + w));
      rans = min(rans, ans);
    } else {
      int l = 1, r = w;
      while (l <= r) {
        int mid = (l + r) >> 1;
        if (ss[mid] < -w)
          r = mid - 1;
        else
          l = mid + 1;
      }
      int x = r + 1;
      int ans =
          max(min(Query1(w + 1, n) - w, Query2(x, w) + w), sss[x - 1] + w);
      rans = min(rans, ans);
    }
  }
  printf("%d\n", rans > 1e7 ? -1 : rans);
}
