import java.util.*;

public class ThirdMaxScore {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        
        if (n < 3) {
            System.out.println("Invalid input");
            return;
        }

        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }

        // Use TreeSet to store distinct values in descending order
        TreeSet<Integer> set = new TreeSet<>(Collections.reverseOrder());
        for (int num : arr) {
            set.add(num);
        }

        // If there are at least 3 distinct numbers
        if (set.size() >= 3) {
            Iterator<Integer> it = set.iterator();
            it.next(); // first max
            it.next(); // second max
            System.out.println(it.next()); // third max
        } else {
            // Less than 3 distinct values → print highest
            System.out.println(set.first());
        }
    }
}