#include<iostream>
#include<stack>
using namespace std;
int main(){
int n;
while(cin>>n,n){
stack<int> p;
for (int i = 0; i < n;++i) {
int num;
cin >> num;
if(p.empty()){
p.push(num);
}
else if(p.top()!=num){
p.pop();
}
else if(p.top()==num){
p.push(num);
}
}
cout << p.top() << endl;
}
}