N,K=list(map(int, input().split()))



x=N%K



if x ==0:

    print((0))

elif abs(x - K) > x:

    print(x)

else:

    print((abs(x - K)))
N,K=list(map(int,input().split()))



a=N//K



ans=min(abs(N-a*K), abs(N-(a+1)*K))

print(ans)
N, K = list(map(int, input().split()))
x = N % K
if x == 0:
    print((0))
elif abs(x - K) > x:
    print(x)
else:
    print((abs(x - K)))

N, K = list(map(int, input().split()))
a = N // K
ans = min(abs(N - a * K), abs(N - (a + 1) * K))
print(ans)

-x = N % K -if x == 0: -    print((0)) -elif abs(x - K) > x: -    print(x) -else: -    print((abs(x - K))) +a = N // K +ans = min(abs(N - a * K), abs(N - (a + 1) * K)) +print(ans)