/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scanner = new Scanner(System.in);
		
		long x = scanner.nextInt();
		long y = scanner.nextInt();
		
		long a;
		while (x % y != 0) {
			a = x;
			x = y;
			y = a % y;
			
		}
		System.out.println(y);
		
	}
} import java.util.*; util.* java import java.lang.*; lang.* java import java.io.*; io.* java class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scanner = new Scanner(System.in);
		
		long x = scanner.nextInt();
		long y = scanner.nextInt();
		
		long a;
		while (x % y != 0) {
			a = x;
			x = y;
			y = a % y;
			
		}
		System.out.println(y);
		
	}
} Main public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scanner = new Scanner(System.in);
		
		long x = scanner.nextInt();
		long y = scanner.nextInt();
		
		long a;
		while (x % y != 0) {
			a = x;
			x = y;
			y = a % y;
			
		}
		System.out.println(y);
		
	} main {
		Scanner scanner = new Scanner(System.in);
		
		long x = scanner.nextInt();
		long y = scanner.nextInt();
		
		long a;
		while (x % y != 0) {
			a = x;
			x = y;
			y = a % y;
			
		}
		System.out.println(y);
		
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) long x = scanner.nextInt(); x scanner.nextInt() scanner.nextInt scanner long y = scanner.nextInt(); y scanner.nextInt() scanner.nextInt scanner long a; a while (x % y != 0) {
			a = x;
			x = y;
			y = a % y;
			
		} x % y != 0 x % y x y 0 {
			a = x;
			x = y;
			y = a % y;
			
		} a = x a x x = y x y y = a % y y a % y a y System.out.println(y) System.out.println System.out System System.out y String[] args args
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scanner = new Scanner(System.in);
		
		long x = scanner.nextInt();
		long y = scanner.nextInt();
		
		long a;
		while (x % y != 0) {
			a = x;
			x = y;
			y = a % y;
			
		}
		System.out.println(y);
		
	}
}
