#include <bits/stdc++.h>
using namespace std;
const int T = 1000000 + 50;
struct node {
  int v, id;
} a[T];
int main() {
  int n, m, i, j, k;
  while (~scanf("%d", &n)) {
    memset(a, 0, sizeof(a));
    int ma = 0, k = 0, t = 0;
    for (i = 0; i < n; ++i) {
      scanf("%d", &m);
      a[m].v++;
      a[m].id = i;
    }
    for (i = 0; i < T; ++i)
      if (k < a[i].v || (k == a[i].v && t >= a[i].id))
        k = a[i].v, t = a[i].id, ma = i;
    printf("%d\n", ma);
  }
  return 0;
}
