/**
 * Created by IntelliJ IDEA.
 * User: m09ega
 * Date: 07.10.2009
 * Time: 18:34:46
 * To change this template use File | Settings | File Templates.
 */
import java.util.*;
import java.io.*;

public class PrC {
    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();
        while(a!=b){
            if (a>b){
                a=a-b;
            } else if(a<b){
                b=b-a;
            }
        }
        out.println(a);
        in.close();
        out.close();
    }
}
