#include <bits/stdc++.h>

typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define DECIM8  fixed<<setprecision(8) 
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

using namespace std;
// dx,cost
int main(void)
{
  int n;
  cin >> n;
  vector<pair<int,int> > adj[131072];
  REP(i,n){
    int tmp;
    cin >> tmp;
    if(tmp) adj[i].push_back(make_pair(tmp,0));
    else REP(j,6) adj[i].push_back(make_pair(j+1,1));
  }
  int answer;
  set<int> already;
  priority_queue<pair<int,int> >dijk;
  dijk.push(make_pair(-0,0));
  while(!dijk.empty()){
    int ncos,x;
    tie(ncos,x)=dijk.top();
    dijk.pop();
    if(!already.insert(x).second) continue;
    if(x==n-1){
      cout << -ncos << endl;
      return 0;
    }
    REP(i,adj[x].size()){
      int dx,cost;
      tie(dx,cost)=adj[x][i];
      dijk.push(make_pair(ncos-cost,x+dx));
    }
  }
  return 0;
}