import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; import java.util.stream.Collectors; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int size = in.nextInt(); in.nextLine(); String[] typesArray = in.nextLine().split("\\s"); List listTypes = Arrays.asList(typesArray); Set uniqueTypes = new HashSet(listTypes); HashMap countMap = new HashMap<>(); List countList = uniqueTypes.stream() .map(x -> { int count = (int) listTypes.stream() .filter(y -> { return Integer.valueOf(y) == Integer.valueOf(x); }) .count(); countMap.put(x, count); return count; }) .collect(Collectors.toList()); int max = countList.stream() .max((a, b) -> Integer.compare(a, b)) .get(); int maxOccurrence = (int) countList.stream() .filter(z -> z == max) .count(); if (maxOccurrence > 1) { List minList = new ArrayList<>(); countMap.forEach((key, value) -> { if (value == max) minList.add(Integer.valueOf(key)); }); int min = minList.stream() .min((a, b) -> Integer.compare(a,b)) .get(); System.out.println(min); } else { countMap.forEach((key, value) -> { if (value == max) System.out.println(key); }); } } }