1 #include <iostream>
2 #include <algorithm>
3 #include <vector>
4
5 int main() {
6 int x{},y{},lenth{};
7 std::cin >> x;
8 std::vector<std::vector<int>> n(x+1, std::vector<int>(2,0));
9
10 for (int i{}; i < x; i++) {
11 std::cin >> y;
12 bool bo{ true };
13
14 for (int j{lenth}; j >= 0; j--) {
15 if (y == n[j][0]) {
16 n[j][1]++;
17 bo = false;
18 }
19 else if (bo && (j == 0)) {
20 n[lenth][0] = y;
21 n[lenth][1]++;
22 lenth++;
23 }
24 }
25 }
26 std::sort(std::begin(n), std::end(n), [](std::vector<int>& a, std::vector<int>& b) {return a[1] > b[1]; });
27
28 int min{n[0][0]}, z{};
29 while (n[z][1] == n[z + 1][1]) {
30 if (min > n[z + 1][0]) {
31 min = n[z + 1][0];
32 }
33 z++;
34 }
35 std::cout << min;
36 }