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

/**
 * Created by IntelliJ IDEA.
 * User: m09aya
 * Date: 07.10.2009
 * Time: 18:21:47
 * To change this template use File | Settings | File Templates.
 */
public class P {
    public static void main (String [] args) throws Exception {
        Scanner in = new Scanner (new File ("gcd.in"));
        PrintWriter out = new PrintWriter (new File("gcd.out"));
        int a = in.nextInt();
        int b = in.nextInt();
        if (a<0) {a=-a;} if (b<0){b=-b;}
        if (b<a) { int i= a; a=b; b=i;}
          while (b!=0){
                        int d = a/b;
                        a = a - d*b;
                        d = a;
                        a = b;
                        b = d;
                      }
               out.print(a);
        in.close();
        out.close();

    }
}
