program forum;

const
    maxn = 1000;
    maxlen = 30;

var
    i, p, j, n, tn, max: longint;
    t: array [1..maxn] of longint;
    num: array [1..maxn] of longint;
    topic: array [1..maxn] of string[maxlen];
    c: char;

begin
{    assign(input, 'forum.in');
    reset(input);
    assign(output, 'forum.out');
    rewrite(output);}

    readln(n);
    for i := 1 to n do
    begin
        readln(p);
        if p = 0 then
        begin
            inc(tn);
            t[i] := tn;
            num[tn] := 1;
            readln(topic[tn]);
        end else begin
            t[i] := t[p];
            inc(num[t[i]]);
        end;
        readln;
    end;

    max := 1;
    for i := 2 to tn do
    begin
        if num[i] > num[max] then
            max := i;
    end;

    writeln(topic[max]);

    close(input);
    close(output);
end.
