It is planned to send an expedition to a neighbouring star system. n candidates were selected, numbered from 1 to n, among whom it was necessary to select the expedition members. The organisers want to send as many candidates as possible to the expedition.
A survey was conducted among the candidates, during which everyone could indicate no more than one of the other candidates with whom he was not ready to go to expedition. The result of the survey for the i - th candidate is an integer a[i]
, that equals to the number of the candidate with whom the i - th candidate is not ready to go to expedition, or -1, if i - th candidate is ready to go to expedition in any composition.
Now the organisers must choose which of the candidates will go to expedition. It was decided to select the expedition members so that if some candidate i and a[i]
≠ -1 enter there, then candidate a[i]
does not enter there. Organisers want to choose the maximum number of expedition members.
Write a program that determines the maximum number of candidates who can be sent to expedition based on the results of a survey of candidates.
First line contains one integer n (1 ≤ n ≤ 300 000) - the number of candidates. The following n lines give the results of the survey, the i - th of these lines contains the result of survey of the i - th candidate, an integer a[i]
(a[i]
= -1 or 1 ≤ a[i]
≤ n, a[i]
≠ i).
Print a single integer - the maximum number of candidates who can be sent to expedition.