#include <bits/stdc++.h>
using namespace std;
int arr[10000001 + 1];
int ind[10000001 + 1];
int main() {
  int n, ans = 10000001 + 2, out;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", arr + i);
  }
  for (int i = 0; i <= 10000001; i++) ind[i] = -1;
  for (int i = 0; i < n; i++) ind[arr[i]] = max(ind[arr[i]], i);
  for (int i = 0; i <= 10000001; i++) {
    if (ind[i] < ans && ind[i] != -1) {
      out = i;
      ans = min(ans, ind[i]);
    }
  }
  printf("%d\n", out);
  return 0;
}
