program main
  
  implicit none
  integer(8) :: n, k
  
  read(*,*) n, k
  
  if( mod(n,k) < abs( mod(n,k) - k ) ) then
    print*, mod(n,k) 
  else
    print*, abs( mod(n,k) - k )
  end if
  
end program main
