#include <stdio.h>
#include <stdlib.h>

int main()
{
    long a, b,c;
    scanf("%ld %ld", &a, &b);
    if(b==1){
        a = 1;
    }
    while (1)
    {
        c＝labs(a-b);
    
                if(c>=a)
                    break;
      
                a = c;
    }

    if(a==b)
        a = 0;
    printf("%ld\n", a);
}