#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int arr[n];
  map<long long int, long long int> mp1;
  map<long long int, long long int> mp2;
  for (long long int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (long long int i = 0; i < n; i++) {
    mp1[arr[i]] += 1;
    mp2[arr[i]] = i;
  }
  long long int m = INT_MIN;
  for (long long int i = 0; i < n; i++) {
    if (m < mp1[arr[i]]) {
      m = mp1[arr[i]];
    }
  }
  long long int ans;
  long long int pos = INT_MAX;
  for (long long int i = 0; i < n; i++) {
    if (mp1[arr[i]] == m) {
      if (mp2[arr[i]] < pos) {
        pos = mp2[arr[i]];
        ans = arr[i];
      }
    }
  }
  cout << ans << endl;
}
