#include <bits/stdc++.h>
using namespace std;
int n, a[1500000][2], maxx = 0, ii = 10000000, cur;
int main() {
  cin >> n;
  memset(a, 0, sizeof(a));
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    a[x][0]++;
    a[x][1] = i;
  }
  for (int i = 0; i < 1100000; ++i) {
    if (a[i][0] > maxx) {
      maxx = a[i][0];
      ii = a[i][1];
      cur = i;
    }
    if (a[i][0] == maxx && a[i][1] < ii) {
      ii = a[i][1];
      cur = i;
    }
  }
  cout << cur;
  return 0;
}
