import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;

class Node{
	Node[] kids;
	Node parent;
	int id;
	int _value;
	bool done = false;
	this(int id){
		this.id = id;
		}
	void setParent(Node parent){
		this.parent = parent;
		parent.kids ~= this;
		}
	void pushTo(Node[] stack){
		stack ~= this;
		foreach(k; kids) k.pushTo(stack);
		}
	int value(){
		if(!done){
			int max = 0;
			int count = 0;
			foreach(k; kids){
				if(k.value > max) max = k.value, count = 1;
				else if(k.value == max) count += 1;
				}
			this._value = max + count;
			this.done = true;
			}
		return _value;
		}
	}

void main(){
	int n = readln.chomp.to!int;
	Node[] nodes;
	for(int i = 0; i < n; i ++) nodes ~= new Node(i);
	for(int i = 1; i < n; i ++){
		int a = readln.chomp.to!int - 1;
		nodes[i].setParent(nodes[a]);
		}
	
	debug writeln(nodes.map!(x => x.parent? x.parent.id: -1));
	
	int ans = nodes[0].value;
	
	debug writeln(nodes.map!(x => x.value));
	
	ans.writeln;
	}