#include <bits/stdc++.h>
using namespace std;
int hs[1000005] = {0};
int pos[1000005] = {0};
int main() {
  int n, i, x, max;
  cin >> n;
  int arr[n];
  for (i = 1; i <= n; i++) cin >> arr[i];
  for (i = 1; i <= n; i++) {
    hs[arr[i]]++;
    pos[arr[i]] = i;
  }
  max = hs[1];
  x = 1;
  for (i = 1; i <= 1000000; i++) {
    if (max < hs[i]) {
      max = hs[i];
      x = i;
    } else if (max == hs[i]) {
      if (pos[x] > pos[i]) {
        max = hs[i];
        x = i;
      }
    }
  }
  cout << x;
  return 0;
}
