import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int num1 = Integer.parseInt(s.next());
		int num2 = Integer.parseInt(s.next());
		int sub;
		
		if(num2 > num1){
			sub = num2;
			num2 = num1;
			num1 = sub;
		}
		
		while(num1 != num2){
			sub = num1;
			num1 = Math.max(num1 - num2, num2);
			num2 = Math.min(sub - num2, num2);
		}
		
		System.out.println(num1);
		
	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int num1 = Integer.parseInt(s.next());
		int num2 = Integer.parseInt(s.next());
		int sub;
		
		if(num2 > num1){
			sub = num2;
			num2 = num1;
			num1 = sub;
		}
		
		while(num1 != num2){
			sub = num1;
			num1 = Math.max(num1 - num2, num2);
			num2 = Math.min(sub - num2, num2);
		}
		
		System.out.println(num1);
		
	}

} Main public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int num1 = Integer.parseInt(s.next());
		int num2 = Integer.parseInt(s.next());
		int sub;
		
		if(num2 > num1){
			sub = num2;
			num2 = num1;
			num1 = sub;
		}
		
		while(num1 != num2){
			sub = num1;
			num1 = Math.max(num1 - num2, num2);
			num2 = Math.min(sub - num2, num2);
		}
		
		System.out.println(num1);
		
	} main {
		Scanner s = new Scanner(System.in);
		int num1 = Integer.parseInt(s.next());
		int num2 = Integer.parseInt(s.next());
		int sub;
		
		if(num2 > num1){
			sub = num2;
			num2 = num1;
			num1 = sub;
		}
		
		while(num1 != num2){
			sub = num1;
			num1 = Math.max(num1 - num2, num2);
			num2 = Math.min(sub - num2, num2);
		}
		
		System.out.println(num1);
		
	} Scanner s = new Scanner(System.in); s new Scanner(System.in) int num1 = Integer.parseInt(s.next()); num1 Integer.parseInt(s.next()) Integer.parseInt Integer s.next() s.next s int num2 = Integer.parseInt(s.next()); num2 Integer.parseInt(s.next()) Integer.parseInt Integer s.next() s.next s int sub; sub if(num2 > num1){
			sub = num2;
			num2 = num1;
			num1 = sub;
		} num2 > num1 num2 num1 {
			sub = num2;
			num2 = num1;
			num1 = sub;
		} sub = num2 sub num2 num2 = num1 num2 num1 num1 = sub num1 sub while(num1 != num2){
			sub = num1;
			num1 = Math.max(num1 - num2, num2);
			num2 = Math.min(sub - num2, num2);
		} num1 != num2 num1 num2 {
			sub = num1;
			num1 = Math.max(num1 - num2, num2);
			num2 = Math.min(sub - num2, num2);
		} sub = num1 sub num1 num1 = Math.max(num1 - num2, num2) num1 Math.max(num1 - num2, num2) Math.max Math num1 - num2 num1 num2 num2 num2 = Math.min(sub - num2, num2) num2 Math.min(sub - num2, num2) Math.min Math sub - num2 sub num2 num2 System.out.println(num1) System.out.println System.out System System.out num1 String[] args args public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int num1 = Integer.parseInt(s.next());
		int num2 = Integer.parseInt(s.next());
		int sub;
		
		if(num2 > num1){
			sub = num2;
			num2 = num1;
			num1 = sub;
		}
		
		while(num1 != num2){
			sub = num1;
			num1 = Math.max(num1 - num2, num2);
			num2 = Math.min(sub - num2, num2);
		}
		
		System.out.println(num1);
		
	}

} public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int num1 = Integer.parseInt(s.next());
		int num2 = Integer.parseInt(s.next());
		int sub;
		
		if(num2 > num1){
			sub = num2;
			num2 = num1;
			num1 = sub;
		}
		
		while(num1 != num2){
			sub = num1;
			num1 = Math.max(num1 - num2, num2);
			num2 = Math.min(sub - num2, num2);
		}
		
		System.out.println(num1);
		
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int num1 = Integer.parseInt(s.next());
		int num2 = Integer.parseInt(s.next());
		int sub;
		
		if(num2 > num1){
			sub = num2;
			num2 = num1;
			num1 = sub;
		}
		
		while(num1 != num2){
			sub = num1;
			num1 = Math.max(num1 - num2, num2);
			num2 = Math.min(sub - num2, num2);
		}
		
		System.out.println(num1);
		
	}

}