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

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 int maxPebble = 0;

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

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

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

    return false;
}

int main()
{
    int n;
    while (cin >> n)
    {
        if (n == 0) break;

        pebbles.clear();

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

        pebbles[0].jumped = true;

        find_max(0);

        /*int pebblesVisited = 1;
        int active = 0;
        int oldActive = 0;
        int maxPebble = 0;

        while (active < n - 1)
        {
            oldActive = active;
            for (int i = n - 1; i >= 0; i--)
            {
                if (i == active) continue;

                if (can_jump(pebbles[active], pebbles[i]))
                {
                    active = i;
                    maxPebble = max(maxPebble, i);
                    pebbles[i].jumped = true;
                    pebblesVisited++;
                }
            }

            if (active == oldActive) break;
        }*/

        cout << maxPebble << endl;
    }

    /*int t, f, fu, fn;

    while (cin >> t >> f >> fu >> fn)
    {
        if (t == 0 && f == 0 && fu == 0 && fn == 0) break;

        vector<Node> nodes;

        for (int i = 0; i < f; i++)
        {
            nodes.push_back(Node(i));
        }

        for (int = 0; i < t; i++)
        {
            int from, to;
            double u;

            cin >> from >> to >> u;
            nodes[from - 1].edges.push_back(Edge(from - 1, to - 1, u));
        }

        bfs(nodes, fu - 1, fn - 1);
    }*/



    return 0;
}