Handong Does Not Want to Study!

Time limit1sMemory limit128 MB

Problem

Handong, a member of H-ALGO, does not like studying. Still, he wants to pass a difficult exam without studying.

One day, a classmate tells Handong that one of the seniors might know the answers to the exam. Unfortunately, that information is not quite right. The seniors do not know the answers either; each senior only knows another senior who might know them.

If Handong asks senior i, that senior tells him exactly one senior to ask next. Handong can continue asking the indicated senior in the same way. Once he reaches a senior he has already met, he cannot meet any new senior by continuing the process.

Handong may choose exactly one senior to ask first. Choose the first senior so that Handong meets as many distinct seniors as possible. If there is more than one best choice, choose the senior with the smallest number.

Input

The first line contains an integer N. N is a natural number between 2 and 1000, inclusive. The seniors are numbered from 1 to N.

Each of the next N lines contains one integer. The i-th of these lines is the number of the senior named by senior i.

Output

Print the number of the senior Handong should ask first. If there is more than one correct answer, print the smallest such number.