import java.util.*;
import java.io.*;
public class s1 {
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;
    a=in.nextInt();
int b;
    b = in.nextInt();
    int d;
    if (a<0) a=-a;
    if (b<0) b=-b;
    if (a<b)
    {
    int t=a;
        a=b;
        b=t;
    }
while(b!=0)
{
d=a%b;
a=b;
b=d;
}
out.print(a);
in.close();
out.close();
}
}

