#include <bits/stdc++.h>
int arr[3][1000009];
int main() {
  int max = -1, i, j, n, pos, time = 0, cnt = 0, x, ans;
  for (i = 1; i < 3; i++)
    for (j = 0; j < 1000009; j++) arr[i][j] = 0;
  scanf("%d", &n);
  while (n--) {
    scanf("%d", &x);
    arr[1][x]++;
    time++;
    arr[2][x] = time;
    if (x > max) max = x;
  }
  cnt = arr[1][x];
  ans = arr[2][x];
  pos = x;
  for (i = 1; i <= max; i++) {
    if (arr[1][i] != 0) {
      if (arr[1][i] > cnt) {
        cnt = arr[1][i];
        ans = arr[2][i];
        pos = i;
      } else if (arr[1][i] == cnt)
        if (arr[2][i] < ans) {
          ans = arr[2][i];
          pos = i;
        }
    }
  }
  printf("%d\n", pos);
  return 0;
}
