#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
typedef long long int ll;
using namespace std;
#define INF 0x7FFFFFFF
#define N 200000
int dp[1055];
int value[1055];
const int LIMIT = 1e+9;
int n, m;
ll powf(ll base, ll exp) {
ll res = 1;
while (exp) {
if (exp & 1)
res *= base;
exp >>= 1;
base *= base;
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
for (int i = 0; i < 1001; i++) {
dp[i] = INF;
}
for (int i = 1; i <= n; i++) {
cin >> value[i];
}
dp[1] = 0;
for (int j = 1; j <= value[1]; j++) {
if (1 + j <= n) {
dp[1 + j] = 1;
}
}
for (int i = 2; i <= n; i++) {
if (dp[i] == INF) {
continue;
}
for (int j = 1; j <= value[i]; j++) {
if (i + j <= n) {
dp[i + j] = min(dp[i + j], dp[i] + 1);
}
}
}
if (dp[n] == INF) {
cout << -1;
}
else {
cout << dp[n];
}
return 0;
}