#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <queue>
#include <stack>
#include <unordered_map>

using namespace std;

/*struct Edge
{
    int from, to;
    double u;
    Edge() {}
    Edge(int from, int to, double u) : from(from), to(to), u(u) {}
}

struct Node
{
    int x;
    vector<Edge> edges;

    Node(int x) : x(x) {}
};

void bfs(vector<Node>& nodes, int start, int end)
{
    deque<int> vertices;
    vertices.push_back(start);

    while (vertices.empty())
}
*/
struct Pebble
{
    int index;
    int marks;
    bool jumped;

    Pebble() {}
    Pebble(int index, int marks, bool jumped=false) : index(index), marks(marks), jumped(jumped) {}
};

bool can_jump(Pebble& a, Pebble& b)
{
    return (a.marks + b.marks) == abs(a.index - b.index);
}
static vector<Pebble> pebbles;
static unordered_map<int, int> invalid;
static int maxPebble = 0;
static stack<int> jumps;

/*bool find_max(int position)
{
    //cout << position << endl;

    if (position == pebbles.size() - 1)
    {
        maxPebble = position;
        return true;
    }
    if (invalid.count(position))
    {
        return false;
    }

    bool canJump = false;

    for (int i = pebbles.size() - 1; i >= 0; i--)
    {
        if (i == position) continue;
        if (can_jump(pebbles[i], pebbles[position]) && !pebbles[i].jumped)
        {
            canJump = true;
            maxPebble = max(maxPebble, i);
            pebbles[i].jumped = true;
            jumps.push_back(i);
            bool result = find_max(i);
            pebbles[i].jumped = false;
            jumps.pop();
            if (result)
            {
                return true;
            }
        }
    }

    if (!canJump)
    {
        invalid.emplace(position, 1);
    }

    return false;
}*/

size_t bfs(vector<Pebble>& pebbles)
{
    vector<bool> visited(pebbles.size(), false);
    queue<int> nodes;
    nodes.push(0);

    size_t maxVisited = 0;

    while (!nodes.empty())
    {
        int current = nodes.front();
        nodes.pop();

        if (visited[current])
        {
            continue;
        }
        else visited[current] = true;

        for (size_t i = 0; i < pebbles.size(); i++)
        {
            if (i == current) continue;
            if (visited[i]) continue;
            if (can_jump(pebbles[i], pebbles[current]))
            {
                if (i == pebbles.size() - 1)
                {
                    return i;
                }
                nodes.push(i);
                maxVisited = max(maxVisited, i);
            }
        }
    }

    return maxVisited;
}

int main()
{
    string line;
    int n;
    while (getline(cin, line))
    {
        stringstream sn(line);
        sn >> n;

        if (n == 0) break;

        pebbles.clear();

        getline(cin, line);
        stringstream ss(line);

        for (size_t i = 0; i < n; i++)
        {
            int marks;
            ss >> marks;
            pebbles.push_back(Pebble(i, marks, false));
        }

        cout << bfs(pebbles) << endl;
    }

    return 0;
}