#include <stdio.h>
#include <stdlib.h>
int main(void){
    int num,k,res,a,b;
    scanf("%d %d",&num,&k);
    res = num/k;
    a = res*k;
    b = (res+1)*k;
    a = abs(a - num);
    b = abs(b - num);
    if(a > b)printf("%d",b);
    else printf("%d",a);
}
