#include int min(int a, int b) { if (a < b) return a; else return b; } int r[100005]; int seg[400005], ss; void update(int x, int v) { x += ss - 1; seg[x] = v; while (x > 0) { x = (x - 1) / 2; seg[x] = min(seg[2 * x + 1], seg[2 * x + 2]); } return; } int getmin(int l, int r) { l += ss - 1; r += ss - 1; int res = 1e9; while (l < r) { res = min(res, min(seg[l], seg[r])); l /= 2; r = r / 2 - 1; } if (l == r) res = min(res, seg[l]); return res; } int main() { int n; scanf("%d", &n); int i; for (i = 0; i < n - 1; i++) scanf("%d", &r[i]); for (ss = 1; ss < n; ss *= 2); for (i = 0; i < 2 * ss - 1; i++) seg[i] = 1e9; update(n - 1, 0); for (i = n - 2; i >= 0; i--) update(i, 1 + getmin(i + 1, r[i] - 1)); printf("%d\n", seg[ss - 1]); return 0; }