// #pragma GCC ta g("avx2") // #pragma GCC optimize("Ofast") // #pragma GCC optimize("unroll-loops") #include using namespace std; #define DEBUG #ifdef DEBUG template ostream &operator<<(ostream &os, const pair &p) { os << '(' << p.first << ',' << p.second << ')'; return os; } template ostream &operator<<(ostream &os, const vector &v) { os << '{'; for(int i = 0; i < (int)v.size(); i++) { if(i) { os << ','; } os << v[i]; } os << '}'; return os; } void debugg() { cerr << endl; } template void debugg(const T &x, const Args &... args) { cerr << " " << x; debugg(args...); } #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif using namespace std; typedef long long ll; typedef vector vl; typedef vector vvl; typedef vector vc; typedef vector vs; typedef vector vb; typedef vector vd; typedef pair P; typedef pair pii; typedef vector

vpl; typedef tuple tapu; #define rep(i,n) for(int i=0; i<(n); i++) #define REP(i,a,b) for(int i=(a); i<(b); i++) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() template inline bool chmin(T1 &a,T2 b){ if(a>b){ a = b; return true; } else return false; } template inline bool chmax(T1 &a,T2 b){ if(a inline void print(T &a){ int sz = a.size(); for(auto itr = a.begin(); itr != a.end(); itr++){ cout << *itr; sz--; if(sz) cout << " "; } cout << "\n"; } template inline void print2(T1 a, T2 b){ cout << a << " " << b << "\n"; } template inline void print3(T1 a, T2 b, T3 c){ cout << a << " " << b << " " << c << "\n"; } void mark() {cout << "#" << "\n";} ll pcount(ll x) {return __builtin_popcountll(x);} //#include //using namespace atcoder; const int inf = (1<<30)-1; const ll linf = 1LL<<61; const int MAX = 20200000; int dy[8] = {0,1,0,-1,1,-1,-1,1}; int dx[8] = {-1,0,1,0,1,-1,1,-1}; const double pi = acos(-1); const double eps = 1e-9; const int mod = 1e9 + 7; //const int mod = 998244353; template struct Segtree { using F = function; int sz; vector seg; const F f; const Monoid M; Segtree(int n, const F f, const Monoid &M) : f(f), M(M){ sz = 1; while(sz < n) sz <<= 1; seg.assign(2*sz, M); } void set(int k, const Monoid &x) { seg[k + sz] = x; } void build(){ for(int k=sz-1; k>0; k--){ seg[k] = f(seg[2*k], seg[2*k+1]); } } void update(int k, const Monoid &x){ k += sz; seg[k] = x; while(k >>= 1){ seg[k] = f(seg[2*k], seg[2*k+1]); } } Monoid query(int a, int b){ Monoid L = M, R = M; for(a += sz, b += sz; a < b; a >>= 1, b >>= 1){ if(a & 1) L = f(L, seg[a++]); if(b & 1) R = f(seg[--b], R); } return f(L, R); } Monoid operator[](const int &k) const { return seg[k + sz]; } template int find_subtree(int a, const C &check, Monoid &M0, bool type){ while(a < sz){ Monoid nxt = type ? f(seg[2*a+type],M0) : f(M0,seg[2*a+type]); if(check(nxt)) a = 2 * a + type; else M0 = nxt, a = 2 * a + 1 - type; } return a - sz; } template int find_first(int a, const C &check){ Monoid L = M; if(a <= 0){ if(check(f(L, seg[1]))) return find_subtree(1,check,L,false); return -1; } int b = sz; for(a += sz, b += sz; a < b; a >>= 1, b >>= 1){ if(a & 1){ Monoid nxt = f(L, seg[a]); if(check(nxt)) return find_subtree(a,check,L,false); L = nxt; ++a; } } return -1; } template int find_last(int b, const C &check){ Monoid R = M; if(b >= sz){ if(check(f(seg[1], R))) return find_subtree(1,check,R,true); return -1; } int a = sz; for(b += sz; a < b; a >>= 1, b >>= 1){ if(b & 1){ Monoid nxt = f(seg[--b], R); if(check(nxt)) return find_subtree(b,check,R,true); R = nxt; } } return -1; } }; int main(){ int n; cin >> n; vl r(n-1); rep(i,n-1) cin >> r[i]; Segtree seg(n,[](int a, int b){return min(a,b);},inf); seg.update(n-1,0); for(int i=n-2; i>=0; i--){ seg.update(i,seg.query(i+1,r[i])+1); } cout << seg[0] << "\n"; }