/**
 * Created by IntelliJ IDEA.
 * User: m09aaa
 * Date: 30.09.2009
 * Time: 17:27:57
 * To change this template use File | Settings | File Templates.
 */

/**
 * Created by IntelliJ IDEA.
 * User: m09aaa
 * Date: 30.09.2009
 * Time: 17:27:57
 * To change this template use File | Settings | File Templates.
 */
import java.util.*;
 import java.io.*;

   public class XD {
        public static void main ( String[] args ) throws Exception {
       Scanner in=new Scanner (new File("gcd.in"));
            int x=in.nextInt();
            int y=in.nextInt();
            int d;
            while (x!=y)
              { if (x>y) {d=x/y; x=x-y*d;}
                if (x<y) {d=y/x; y=y-x*d;}}
            
                        PrintWriter out=new PrintWriter (new File("gcd.out"));
                       out.println(x);
                      out.close ();
   }
   }


