#include<stdio.h>
#include<math.h>
int main(){
    long long int x,k,count = 0 ;
    scanf("%lld %lld",&x,&k);
    while(1){
        count = x;
        x = x-k;
        if(x < 0){
            if(count < abs(x)){
                printf("%lld\n",count);
                break;
            }
            else{
                printf("%lld\n",abs(x));
                break;
            }
        }
    }
    return 0;
}