#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<long long int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  map<long long int, pair<int, int> > hash_tree;
  for (int i = 0; i < N; i++) {
    if (hash_tree.find(A[i]) == hash_tree.end()) {
      hash_tree.insert(make_pair(A[i], make_pair(1, i)));
    } else {
      (hash_tree.find(A[i])->second).first++;
      (hash_tree.find(A[i])->second).second = i;
    }
  }
  int max_count = INT_MIN, index = INT_MAX;
  long long int result;
  for (auto it = hash_tree.begin(); it != hash_tree.end(); it++) {
    if (max_count < (*it).second.first) {
      max_count = (*it).second.first;
      index = (*it).second.second;
      result = (*it).first;
    } else if (max_count == (*it).second.first) {
      if (index > (*it).second.second) {
        index = (*it).second.second;
        result = (*it).first;
      }
    }
  }
  cout << result << "\n";
  return 0;
}
