#include <bits/stdc++.h>
using namespace std;
int n, a[1000001], b[1000001], i, k;
int main() {
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> k;
    a[k]++;
    b[k] = i;
  }
  int m = 0;
  for (i = 0; i < 1000001; i++) {
    if (a[i] > a[m]) m = i;
    if (a[i] == a[m] && b[i] < b[m]) m = i;
  }
  cout << m << endl;
}
