#include <bits/stdc++.h>
using namespace std;
const int SIZE = 1000000;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  vector<pair<int, int> > cnt(SIZE + 1);
  for (int i = 0; i <= SIZE; i++) {
    cnt[i] = make_pair(0, -1);
  }
  for (int i = 0; i < n; i++) {
    int v;
    scanf("%d", &v);
    a[i] = v;
    cnt[v].first++;
    cnt[v].second = i;
  }
  int ans = 0, maxv = 0, maxi = 1 << 28;
  for (int i = 1; i <= SIZE; i++) {
    if (cnt[i].first > maxv) {
      maxv = cnt[i].first;
      maxi = cnt[i].second;
      ans = i;
    } else if (cnt[i].first == maxv) {
      if (cnt[i].second < maxi) {
        maxv = cnt[i].first;
        maxi = cnt[i].second;
        ans = i;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
