import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;


public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		int a,b,c;
        Scanner scan=new Scanner(System.in);
        a=scan.nextInt();
        b=scan.nextInt();
        while(a!=0)
        {
        	if(a>=b)
            {
            	a=a%b;
            }
             else if(b>a)
        	{
        		c=b;
        		b=a;
        		a=c;
        		a=a%b;
        	}
        }
        System.out.println(b);
        
	}

} import java.util.*; util.* java import java.io.*; io.* java import static java.util.Arrays.*; import static java.util.Arrays.*; import static java.util.Arrays.*; import static java.util.Collections.*; import static java.util.Collections.*; import static java.util.Collections.*; import static java.lang.Math.*; import static java.lang.Math.*; import static java.lang.Math.*; public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		int a,b,c;
        Scanner scan=new Scanner(System.in);
        a=scan.nextInt();
        b=scan.nextInt();
        while(a!=0)
        {
        	if(a>=b)
            {
            	a=a%b;
            }
             else if(b>a)
        	{
        		c=b;
        		b=a;
        		a=c;
        		a=a%b;
        	}
        }
        System.out.println(b);
        
	}

} Main public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		int a,b,c;
        Scanner scan=new Scanner(System.in);
        a=scan.nextInt();
        b=scan.nextInt();
        while(a!=0)
        {
        	if(a>=b)
            {
            	a=a%b;
            }
             else if(b>a)
        	{
        		c=b;
        		b=a;
        		a=c;
        		a=a%b;
        	}
        }
        System.out.println(b);
        
	} main {
		// TODO ?????????????????????????????????????????????
		int a,b,c;
        Scanner scan=new Scanner(System.in);
        a=scan.nextInt();
        b=scan.nextInt();
        while(a!=0)
        {
        	if(a>=b)
            {
            	a=a%b;
            }
             else if(b>a)
        	{
        		c=b;
        		b=a;
        		a=c;
        		a=a%b;
        	}
        }
        System.out.println(b);
        
	} int a a b b c; c Scanner scan=new Scanner(System.in); scan new Scanner(System.in) a=scan.nextInt() a scan.nextInt() scan.nextInt scan b=scan.nextInt() b scan.nextInt() scan.nextInt scan while(a!=0)
        {
        	if(a>=b)
            {
            	a=a%b;
            }
             else if(b>a)
        	{
        		c=b;
        		b=a;
        		a=c;
        		a=a%b;
        	}
        } a!=0 a 0 {
        	if(a>=b)
            {
            	a=a%b;
            }
             else if(b>a)
        	{
        		c=b;
        		b=a;
        		a=c;
        		a=a%b;
        	}
        } if(a>=b)
            {
            	a=a%b;
            }
             else if(b>a)
        	{
        		c=b;
        		b=a;
        		a=c;
        		a=a%b;
        	} a>=b a b {
            	a=a%b;
            } a=a%b a a%b a b if(b>a)
        	{
        		c=b;
        		b=a;
        		a=c;
        		a=a%b;
        	} b>a b a {
        		c=b;
        		b=a;
        		a=c;
        		a=a%b;
        	} c=b c b b=a b a a=c a c a=a%b a a%b a b System.out.println(b) System.out.println System.out System System.out b String[] args args public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		int a,b,c;
        Scanner scan=new Scanner(System.in);
        a=scan.nextInt();
        b=scan.nextInt();
        while(a!=0)
        {
        	if(a>=b)
            {
            	a=a%b;
            }
             else if(b>a)
        	{
        		c=b;
        		b=a;
        		a=c;
        		a=a%b;
        	}
        }
        System.out.println(b);
        
	}

} public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		int a,b,c;
        Scanner scan=new Scanner(System.in);
        a=scan.nextInt();
        b=scan.nextInt();
        while(a!=0)
        {
        	if(a>=b)
            {
            	a=a%b;
            }
             else if(b>a)
        	{
        		c=b;
        		b=a;
        		a=c;
        		a=a%b;
        	}
        }
        System.out.println(b);
        
	}

} Main
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;


public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		int a,b,c;
        Scanner scan=new Scanner(System.in);
        a=scan.nextInt();
        b=scan.nextInt();
        while(a!=0)
        {
        	if(a>=b)
            {
            	a=a%b;
            }
             else if(b>a)
        	{
        		c=b;
        		b=a;
        		a=c;
        		a=a%b;
        	}
        }
        System.out.println(b);
        
	}

}