12574 - New Year   

Description

Bob is a young kid. He thinks New Year is a tradition that involves many troublesome events such as family reunion, etc. Luckily, there is always one event that can cheer him up - receiving red envelopes.

His family tree looks like this :

However, only his parents, uncles (disregard uncle-in-law), aunts (disregard aunt-in-law), grandparents, grand-grandparents, grand-...-grandparents will give him one red envelope in New Year's Eve (circled in the family tree), so the family tree he cares looks like the following graph.  Bob calls this version of family tree "New Year Family Tree".  (Relatives in blue nodes are those who will give Bob red envelopes)

Since Bob has a large family, he can receive many red envelopes in New Year's Eve.  Given Bob's "New Year Family Tree", please tell Bob how many envelopes he can get.

Input

The input is in the following format :

 N
 P1 P2 P3 ... PN
  • N is an integer which means there are N people in the "New Year Family Tree" (including Bob). People are numbered from 1 to N. Bob is numbered with N.

  • There are N integers in the second line. Pi (the i-th number counted from the left) is the parent of person i. If Pi = -1, it means that person i 's parent is too old and has passed away.

Technical Restrictions

  • 1 <= N <= 10^5

  • 1 <= Pi <= N or Pi = -1

  • Only the oldest grand-...-grandparents has passed away in the "New Year Family Tree"

 

Output

Output how many red envelopes Bob will get.  Remember to add a newline character in the end.

Sample Input  Download

Sample Output  Download

Tags

8 555



Discuss