#include<stdio.h>
#include<math.h>
int main()
{
    unsigned long long int x, y,z;
    scanf("%lld %lld", &x, &y);

    if(abs(x-y)<x)
    {
        while(abs(x-y)<x)
        {
            z = abs(x-y);
            x = z;
        }

        printf("%lld", z);

    }

    else
    {
        printf("%lld", x);
    }



    return 0;
}
