After multiple attempts I still can't solve this - please help
package com.codegym.task.task05.task0532;
import java.io.*;
import java.lang.*;
import static java.lang.Integer.MIN_VALUE;
/*
Task about algorithms
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int maximum = Integer.MIN_VALUE;
int N = Integer.parseInt(reader.readLine());
while (N <= 0 ){
int M = Integer.parseInt(reader.readLine());
if (M > 0)
N = M ;
}
for (int i = 0; i < N ; i++) {
int N2 = Integer.parseInt(reader.readLine());
if (N2 > N ) {
if (N2 > maximum)
maximum = N2;
}
else {
if (N > maximum)
maximum = N;
}
}
if (N > 0 )
System.out.println(maximum);
}
}