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

int main () {
    long long int n, k, min;

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

    do {
        min = n;
        n = abs(n - k);
    } while (n < min);

    printf("%lld", min);

    return 0;
}