#include <bits/stdc++.h>
using namespace std;
int used[1000007];
int winner[1000007];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  std::ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int A[n];
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    used[A[i]]++;
  }
  int xam = -7;
  for (int i = 1; i <= 1000001; i++) {
    if (used[i] > xam) {
      xam = used[i];
    }
  }
  for (int i = 1; i <= 1000001; i++) {
    if (used[i] == xam) {
      winner[i] = 1;
    }
  }
  fill(used, used + 1000007, 0);
  for (int i = 0; i < n; i++) {
    used[A[i]]++;
    if (winner[A[i]] == 1 && used[A[i]] == xam) {
      cout << A[i];
      return 0;
    }
  }
  return 0;
}
