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 n=in.nextLong();
        long s = 0;
        while (n>0){
            s=s+n%10;
            n=n/10;
        }
        out.println(s);*/
        long a=in.nextLong();
        long b=in.nextLong();
        while (a!=b){
            if (a>b){
                a=a-b;
            }
            else{
                b=b-a;
            }
        }
        out.println(a);
        out.close();
    }
 }
