#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<int, pair<int, int> > mp;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (mp.find(x) != mp.end()) {
      mp[x] = make_pair(mp[x].first + 1, i);
    } else {
      mp[x] = make_pair(1, i);
    }
  }
  map<int, pair<int, int> >::iterator k;
  int maxm = 0, p = 99999;
  int candidate = -1;
  for (k = mp.begin(); k != mp.end(); k++) {
    pair<int, int> top = (*k).second;
    if (top.first == maxm) {
      if (top.second < p) {
        candidate = (*k).first;
        p = top.second;
      }
    } else if (top.first > maxm) {
      maxm = top.first;
      candidate = (*k).first;
      p = top.second;
    }
  }
  cout << candidate << endl;
  return 0;
}
