import java.util.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); Map birdsMap = new HashMap<>(); for (int i = 0; i < n; i++) { int type = in.nextInt(); Birds key = new Birds(type); Birds birds = birdsMap.getOrDefault(key, key); birds.increment(); birdsMap.put(key, birds); } List birdsList = new ArrayList<>(birdsMap.values()); Collections.sort(birdsList, new Comparator() { @Override public int compare(Birds o1, Birds o2) { if (o1.getCount() == o2.getCount()) { return o1.getType() - o2.getType(); } return o2.getCount() - o1.getCount(); } }); //System.out.println(birdsList.toString()); System.out.println(String.valueOf(birdsList.get(0).getType())); } static class Birds { private final int type; private int count; public Birds(int type) { this.type = type; } public int getCount() { return count; } public int getType() { return type; } public void increment() { count++; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; return type == ((Birds) o).type; } @Override public int hashCode() { return type; } @Override public String toString() { return "Birds{" + "type=" + type + ", count=" + count + '}'; } } }