Может, вообще не тем боком пытаюсь сделать?
package com.javarush.task.task05.task0532;
import java.io.*;
/*
Задача по алгоритмам
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int maximum = 0;
int nmb = Integer.parseInt(reader.readLine());
for (int a = 0; a <= nmb; a++) {
int n = Integer.parseInt(reader.readLine());
if (n >= maximum && n != 0) {
maximum = n;
int x = Integer.parseInt(reader.readLine());
if (x >= n)
maximum = x;
else
maximum = n;
}
else
maximum = maximum;
}
System.out.println(maximum);
}
}