#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1000005;
struct name {
  int x, i;
};
name x[MAX_N];
int main() {
  int n, a, maxi = 0;
  cin >> n;
  for (int i = 0; i < MAX_N; i++) {
    x[i].x = 0;
    x[i].i = -1;
  }
  for (int i = 0; i < n; i++) {
    cin >> a;
    x[a].x++;
    x[a].i = i + 1;
  }
  for (int i = 0; i < MAX_N; i++) {
    if (x[i].x > x[maxi].x || x[maxi].x == x[i].x && x[maxi].i > x[i].i) {
      maxi = i;
    }
  }
  cout << maxi;
}
