#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<int, int> > v(1000001);
  for (int i = 0; i < n; ++i) {
    int num;
    cin >> num;
    v[num].first++;
    v[num].second = i;
  }
  int mx = 0;
  int ans = 0;
  int time = 0;
  for (int i = 0; i < 1000001; ++i) {
    if (v[i].first > mx || (v[i].first == mx && v[i].second < time))
      mx = v[i].first, ans = i, time = v[i].second;
  }
  cout << ans;
  return 0;
}
