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

int main (int argc, char *argv[]) {
    long long int n, k, menor;

    scanf("%lld %lld", &n, &k);

    while (abs(n) > abs(n - k)) {
        n = abs(n - k);
    }

    if (n >= 1000000000000000000 || n == 0) {
        printf("0");
        return 0;
    }

    printf("%lld", n);

    return 0;
}