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

 public class gcd {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(new File("gcd.in"));
        PrintWriter out = new PrintWriter("gcd.out");
        long a=in.nextLong();
        long b=in.nextLong();
        if (a==0 || b==0){
            if (a==0){
            a=b;
        }
        }
        else{
        while (a!=b){
            if (a>b){
                if ((a%b)!=0){
                    a=a%b;
                }
                else{
                    a=b;
                }
            }
            else{
                if ((b%a)!=0){
                    b=(b%a);
                }
                else{
                    b=a;
                }
            }
        }
        }
        out.println(a);
        out.close();
    }
 }
