#include <stdio.h>
int find_duplicate(int arr[], int n) {
// Your logic here
int slow = arr[n -1];
int fast = arr[n -1];
do {
slow = arr[slow];
fast = arr[arr[fast]];
} while (slow != fast);
slow = arr[n - 1];
while (slow != fast) {
slow = arr[slow];
fast = arr[fast];
}
return slow;
}
int main() {
int n;
scanf("%d", &n);
int arr[100];
for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
int result = find_duplicate(arr, n);
printf("%d", result);
return 0;
}