В IDE все работает. Значение выводится корректное.
package com.javarush.task.task14.task1420;
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
/*
НОД
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
int m = Integer.parseInt(r.readLine());
if (m<=0) throw new Exception();
int n = Integer.parseInt(r.readLine());
if (n<=0) throw new Exception();
ArrayList<Integer> list = new ArrayList<>();
for (int i = 1; i < m; i++) {
if(m%i==0&&n%i==0){
list.add(i);
}
}
System.out.println(Collections.max(list));
}
}