need hint

package com.codegym.task.task14.task1420;
/*
GCD
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<Integer> number = new ArrayList<>();
ArrayList<Integer> greatest = new ArrayList<>();
for(int i = 0; i<2; i++){
int a = Integer.parseInt(reader.readLine());
if(a>0){
number.add(a);
System.out.println(a); }
else{
i--;
}
}
for (int i = 1; i<=number.get(1); i++){
if(number.get(0)%i==0 && number.get(1)%i==0)
greatest.add(i);
}
Collections.sort(greatest);
System.out.println(greatest.get(greatest.size()-1));
}
}