#include <iostream>
#include <vector>
#include <fstream>
#include <ctime>
#include <random>
#include <algorithm>
#include <cassert>
#include <queue>
#include <cstring>
#include <unordered_map>
using namespace std;

random_device rand_dev;
mt19937_64 generator(rand_dev());
bool used[200000];
vector<int> g[200000];
int d[200000];
void dfs(int i) {
    for(auto x : g[i]) {
        d[x]=d[i]+1;
        dfs(x);
    }
}
main() {
    srand(time(0));
    for(int i = 11; i <= 20; i++) {
        int n = 1+generator()%(100000-1);
        vector<int> p(n-1);
        for(int i = 2; i <= n; i++) p[i-2]=generator()%(i-1)+1;
        ofstream in(string("ezici.") + (i<10?"0":"") + (i<100?"0":"") + to_string(i) + ".in");
        ofstream out(string("ezici.") + (i<10?"0":"") + (i<100?"0":"") + to_string(i) + ".out");
        in << -2 << endl;
        in << n << endl;
        for(auto x : p) in << x << " ";
        in << endl;
        memset(used, 0, sizeof(used));
        memset(d, 0, sizeof(d));
        for(int i = 1; i <= n; i++) g[i].clear();
        for(int i = 0; i < p.size(); i++) {
            g[p[i]].push_back(i+2);
        }
        dfs(1);
        int mx=0;
        for(int i = 1; i <= n; i++) mx=max(mx, d[i]);
        out << mx << endl;
    }
}