.

package com.codegym.task.task14.task1420;
/*
GCD
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<Integer> list1= new ArrayList<>();
ArrayList<Integer> list2= new ArrayList<>();
ArrayList<Integer> list3= new ArrayList<>();
try {
int num1 = Integer.parseInt(reader.readLine());
int num2 = Integer.parseInt(reader.readLine());
//
// if(num1<0 || num1==0 ){
// throw new Exception();
// }
// if(num2<0 || num2==0 ){
// throw new Exception();
// }
if(isPositive(num1)!=true || isPositive(num2)!=true){
throw new Exception();
}
else {
for (int i = 1; i <= num1; i++) {
if (num1 % i == 0) {
list1.add(i);
}
}
for (int i = 1; i <= num2; i++) {
if (num2 % i == 0) {
list2.add(i);
}
}
for (int i = 0; i < list1.size(); i++) {
int n = list1.get(i);
for (Integer num : list2) {
if (n == num) {
list3.add(num);
}
}
}
int max = 0;
for (Integer num : list3) {
if (num > max) {
max = num;
}
}
System.out.println(max);
} }
catch (Exception e){
System.out.println(e);
}
}
public static boolean isPositive(int num){
if(num<=0){
return false;
}
else {
return true;
}
}
}