 program sample1
      implicit none
      
      integer(8) N,K,L1,L2
      read(*,*) N,K
      L1=mod(N,K)
      L2=-(L1-K)
      if (L1>L2) then
      write(*,'(i0)') L2
      else 
      write(*,'(i0)') L1
      end if
      stop 
      end program sample1



