#include <bits/stdc++.h>
using namespace std;
const int N = 1000007;
int n, cnt[N], last[N];
void solve() {
  int maxi = 0;
  scanf("%d", &n);
  for (int iter = 0; iter < (int)(n); ++iter) {
    int id;
    scanf("%d", &id);
    ++cnt[id];
    last[id] = iter;
    maxi = max(maxi, cnt[id]);
  }
  int best = N, ans = -1;
  for (int i = 0; i < (int)(N); ++i) {
    if (cnt[i] == maxi && last[i] < best) {
      best = last[i];
      ans = i;
    }
  }
  printf("%d\n", ans);
}
void testgen() {
  FILE *f = fopen("input.txt", "w");
  srand(time(0));
  fclose(f);
}
int main() {
  solve();
  return 0;
}
