#include <bits/stdc++.h>
using namespace std;
int a[1000010];
int num[1010];
int main() {
  int n, num1 = 0, maxn = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> num[i];
    a[num[i]]++;
  }
  for (int i = 1; i <= 1000000; i++) {
    if (a[i] > maxn) {
      maxn = a[i];
      num1 = i;
    }
    if (a[i] == maxn)
      for (int j = n; j >= 1; j--) {
        if (num[j] == num1) {
          maxn = a[i];
          num1 = i;
        } else if (num[j] == i)
          break;
      }
  }
  cout << num1 << endl;
  return 0;
}
