#include <bits/stdc++.h>
int arr[1000010][2];
int main() {
  std::ios::sync_with_stdio(false);
  int n;
  std::cin >> n;
  int x;
  for (int i = 0; i < n; i++) std::cin >> x, arr[x][0]++, arr[x][1] = i;
  int max = 0, maxi = 1000011, maxt = 1000011;
  for (int i = 0; i < 1000010; i++) {
    if (arr[i][0] > max)
      max = arr[i][0], maxt = arr[i][1], maxi = i;
    else if (arr[i][0] == max && arr[i][1] < maxt)
      maxi = i, maxt = arr[i][1];
  }
  std::cout << maxi << std::endl;
  return 0;
}
