import std; struct S { int pos, cnt; } void main() { int N; readf("%d\n", N); auto R = readln.chomp.split.to!(int[]); --N; R[] -= 1; int res; auto heap = new BinaryHeap!(Array!S, "a.cnt == b.cnt ? a.pos < b.pos : a.cnt > b.cnt")(); heap.insert(S(0, 0)); while (!heap.empty) { auto f = heap.front; heap.popFront; if (f.pos == N) { res = f.cnt; break; } foreach (i; f.pos .. R[f.pos]+1) { heap.insert(S(i, f.cnt+1)); } } res.writeln; }