public class Main {
private static Scanner s = null;
public static void main(String[] args) {
s = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
int max = Integer.MIN_VALUE;
int max2 = Integer.MIN_VALUE;
while (true) {
int number = s.nextInt();
if (number == 0) {
System.out.println(max2);
return;
}
if (number > max2) {
max2 = number;
if (max2 > max) {
int temp = max;
max = max2;
max2 = temp;
}
}