import java.io.*; import java.util.*; // Represents a type of bird, along with its associated count class BirdType { public int id; public int count; public BirdType(int id) { this.id = id; this.count = 0; } } public class Solution { public static void main(String[] args) { List birdTypes = new ArrayList<>(5); Scanner in = new Scanner(System.in); // Initialize our list of bird types for (int i = 1; i <= 5; i++) birdTypes.add(new BirdType(i)); // Read all our data, accumulating a count of each bird type int n = in.nextInt(); for (int i = 0; i < n; i++) birdTypes.get(in.nextInt() - 1).count += 1; // Sort the list birdTypes.sort((t1, t2) -> { int result; // Sort first by count in descending order, then by ID in ascending order result = t2.count - t1.count; if (result == 0) result = t1.id - t2.id; return result; }); // Output the "winning" bird type System.out.println(birdTypes.get(0).id); } }