#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;
}