#include<stdio.h>
#include<math.h>
int main ()
{
 int a,b,p;
 scanf ("%d %d",&a,&b);
 if (a<b)
 {
     p = a;
     a = b;
     b =p;
 }
 int t,r;
 while (1)
 {


     r = (a-b);

     if (r < 0)
     {
         break;
     }
     else
     {a = r;


     }




 }
 t = abs (r);
 printf ("%d\n",t);




    return 0;
}
