/**
 * Created by IntelliJ IDEA.
 * User: m09kaa3
 * Date: 07.10.2009
 * Time: 18:17:56
 * To change this template use File | Settings | File Templates.
 */
import java.io.*;
import java.util.*;
public class gcd {
    public static void main(String[] args) throws Exception{
        Scanner s = new Scanner(new File("gcd.in"));
        PrintWriter p = new PrintWriter(new File("gcd.out"));
        int x= s.nextInt();
        int y= s.nextInt();
        int r=x;
        if(y>x){int t=x;x=y;y=t;}
        while (y!=0){
            x= x%y;
            if(y>x){int t=x;x=y;y=t;}
        }
        p.print(x);
        p.close();
    }
}
