/**
 * Created by IntelliJ IDEA.
 * User: m09aaa
 * Date: 07.09.2009
 * Time: 14:11:09
 * To change this template use File | Settings | File Templates.
 */      import java.util.*;
 import java.io.*;

   public class nusya {
        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 x=in.nextInt();
            long y=in.nextInt();
            if (x<0) {x=x*(-1); }
            if (y<0) {y=y*(-1);}
            if (x==0||x%y==0) {out.println(y);}    else {
            if (y==0||y%x==0) {out.println(x);}  else {
            while (x!=y)
            {  while (x>y) {x=x-y;}
              while (y>x) {y=y-x;}}
                       out.println(x);  } }
                       out.close ();
   }
   }

