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

int main(void)
{
    double inputN, inputK;
    long long int answer = 0;
    scanf("%lf%lf", &inputN, &inputK);
    answer = llround(inputN / inputK);
    if (inputN > inputK * answer)
    {
        answer = inputN - inputK * answer;
    }
    else
    {
        answer = inputK * answer - inputN;
    }
    printf("%lld", answer);
    
    return 0;
}