#include<stdio.h>
int main()
{
    long long int n,k,res1,res2;
    scanf("%lld%lld",&n,&k);
    res1=n%k;
    res2=(n%k)-k;
    res2=res2*-1;
    if(res1<res2)
    {
        printf("%lld\n",res1);
    }
    else
    {
        printf("%lld\n",res2);
    }
}
