#include <bits/stdc++.h>
using namespace std;
int phid[1000001];
int pos[1000001];
int main() {
  memset(phid, 0, 1000001);
  int likes;
  cin >> likes;
  int id[likes];
  for (int i = 0; i < likes; i++) {
    cin >> id[i];
    phid[id[i]]++;
    pos[id[i]] = i;
  }
  int max = -1;
  int ans = -1;
  int poss = 1001;
  for (int i = 0; i < likes; i++) {
    if (phid[id[i]] > max) {
      max = phid[id[i]];
      ans = id[i];
      poss = pos[id[i]];
    } else if (phid[id[i]] == max) {
      if (pos[id[i]] < poss) {
        max = phid[id[i]];
        ans = id[i];
        poss = pos[id[i]];
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
