#include <iostream>
using namespace std;
int main() {
int n=0,max1=0,max2=0,max3=0,x=0,a=0;
cin>>n;
cin>>x;
if(x!=0){
if(x<=n){
max2=x;
max1=n;
}
else{
max2=n;
max1=x;
}
}
if(n!=0){
while(cin>>a){
if(a==0){
break;
}
else if(a!=0){
if(a<=max2){
max3 = a;
}
else if(a>=max2 && a<max1){
max2 = a;
}
else{
max2 = max1;
max1 = a;
}
}
}
}
cout<<max2;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CglpbnQgbj0wLG1heDE9MCxtYXgyPTAsbWF4Mz0wLHg9MCxhPTA7CgkKCWNpbj4+bjsKCWNpbj4+eDsKCWlmKHghPTApewoJCWlmKHg8PW4pewoJCQkJbWF4Mj14OwoJCQkJbWF4MT1uOwoJCQkJfQoJCQkJZWxzZXsKCQkJCQltYXgyPW47CgkJCQkJbWF4MT14OwoJCQkJfQoJfQoJCglpZihuIT0wKXsKCQl3aGlsZShjaW4+PmEpewoJCQlpZihhPT0wKXsKCQkJCWJyZWFrOwoJCQl9CgkJCWVsc2UgaWYoYSE9MCl7CgkJCQlpZihhPD1tYXgyKXsKCQkJCQltYXgzID0gYTsKCQkJCX0KCQkJCWVsc2UgaWYoYT49bWF4MiAmJiBhPG1heDEpewoJCQkJCW1heDIgPSBhOwoJCQkJfQoJCQkJZWxzZXsKCQkJCQltYXgyID0gbWF4MTsKCQkJCQltYXgxID0gYTsKCQkJCX0KCQkJCQoJCQl9CgkJfQoJfQoJY291dDw8bWF4MjsKCQoJCglyZXR1cm4gMDsKfQ==