#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int a[n];
  map<int, int> m, second;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (m[a[i]] == 0) {
      second[a[i]] = i;
      m[a[i]]++;
    } else {
      m[a[i]]++;
      second[a[i]] = i;
    }
  }
  int ans = a[0];
  for (int i = 1; i < n; i++) {
    if (m[ans] < m[a[i]]) {
      ans = a[i];
    } else if (m[ans] == m[a[i]]) {
      if (second[ans] > second[a[i]]) ans = a[i];
    }
  }
  cout << ans << endl;
  return 0;
}
