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

/**
 * Created by IntelliJ IDEA.
 * User: m09dao
 * Date: 07.10.2009
 * Time: 18:12:33
 * To change this template use File | Settings | File Templates.
 */
public class Gcd {
    public static void main(String[] args) throws Exception{
        Scanner in=new Scanner(new File("gcd.in"));
        PrintWriter out=new PrintWriter(new File("gcd.out"));
        long a=in.nextInt();
        long b=in.nextInt();
        if(b!=0)
        {
          long c=a%b;
          while(c!=0)
          {
           a=b;
           b=c;
           c=a%b;
          }
          out.println(b);
        }
        else
          out.println(a);
        in.close();
        out.close();
}
}
