#include <bits/stdc++.h>
using namespace std;
int NumberOfLikes[1000001];
int Place[1000001];
int main() {
  int t;
  cin >> t;
  int MaxLikes = 0;
  for (int i = 0; i < t; i++) {
    int useless;
    cin >> useless;
    NumberOfLikes[useless]++;
    MaxLikes = max(MaxLikes, NumberOfLikes[useless]);
    Place[useless] = i;
  }
  vector<pair<int, int> > mavector;
  for (int i = 0; i < 1000001; i++) {
    if (NumberOfLikes[i] == MaxLikes)
      mavector.push_back(make_pair(Place[i], i));
  }
  sort(mavector.begin(), mavector.end());
  cout << mavector[0].second;
  return 0;
}
