program main
      implicit none
      integer(8) n, k
      integer(8) nmin, i

      read *, n,k
      nmin = n

      do
        n = abs(n-k)
        if ( n <= nmin ) then
                nmin = n
        else if ( n > nmin ) then
                exit
        end if
      end do

      print *, nmin

end program main