n,k = map(int,input().split())

top = n - n//k*k
low = n - ((n//k)+1)*k

ans = min(abs(top),abs(low))
print(ans)
2fdc24abd80dcad6efaa4dd3ffc9e7fbe3a32490
<mask token>

<mask token>
print(ans)

n, k = map(int, input().split())
top = n - n // k * k
low = n - (n // k + 1) * k
ans = min(abs(top), abs(low))
print(ans)

n,k = map(int,input().split())

top = n - n//k*k
low = n - ((n//k)+1)*k

ans = min(abs(top),abs(low))
print(ans)