import java.util.Scanner;
import java.io.File;
import java.io.PrintWriter;

/**
 * Created by IntelliJ IDEA.
 * User: m09fpv
 * Date: 07.10.2009
 * Time: 18:35:37
 * 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"));
  int n=in.nextInt();
  int m=in.nextInt();
    int min,max;
      int t;
   int k=0;
   int nod=0;
     if (m<n){min=m; max=n; }
       else{min=n; max=m; }
    if (min==0){out.print(max);}
      else{
 while(max!=min){
        max=max-min;
          if(max<min){t=max; max=t; min=t;}
                  }
          out.print(max);

                 }
          out.close();
          in.close();
   }
 }