import java.io.*;
import java.util.*;
public class main {
    static int func(int a,int b)
    {
        if(a == b)
            return a;
        if(a>b)
            return func(a-b,b);
        if(a<b)
            return func(a,b-a);
        return 0;
    }

    public static void main(String [] args)throws Exception{
        Scanner in=new Scanner(new File("gcd.in"));
        PrintWriter out=new PrintWriter("gcd.out");
        int a=in.nextInt();
        int b=in.nextInt();
        if(b<0)
        b=b*-1;
        if(a<0)
        a=a*-1;
        out.print(func(a,b));
        out.close();
    }
}
