#include <iostream>
using namespace std;
int main() {
int max1=0, max2=0, temp;
cin >> temp;
while(temp!=0) {
if(temp>=max1) {
max2 = max1;
max1 = temp;
}
else if(temp>max2 && temp<max1) {
max2 = temp;
}
else if(max1==max2) {
if(temp>max1) {
max1 = temp;
}
else {
max2 = temp;
}
}
cin >> temp;
}
cout << max2;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CgkKCWludCBtYXgxPTAsIG1heDI9MCwgdGVtcDsKCWNpbiA+PiB0ZW1wOwoJd2hpbGUodGVtcCE9MCkgewoJCWlmKHRlbXA+PW1heDEpIHsKCQkJbWF4MiA9IG1heDE7CgkJCW1heDEgPSB0ZW1wOwoJCX0KCQllbHNlIGlmKHRlbXA+bWF4MiAmJiB0ZW1wPG1heDEpIHsKCQkJbWF4MiA9IHRlbXA7CgkJfQoJCWVsc2UgaWYobWF4MT09bWF4MikgewoJCQlpZih0ZW1wPm1heDEpIHsKCQkJCW1heDEgPSB0ZW1wOwoJCQl9CgkJCWVsc2UgewoJCQkJbWF4MiA9IHRlbXA7CgkJCX0KCQl9CgkJY2luID4+IHRlbXA7Cgl9Cgljb3V0IDw8IG1heDI7CgoJcmV0dXJuIDA7Cn0=