program answer
  implicit none
  integer(16) :: N, i, ans
  read(*,*) N
  do i = int(sqrt(2.0_8*N)), 2*N
     if(mod(i*(i+1)/2,N)==0) then
        write(*,*) i
        exit
     end if
  end do

  stop
 end program answer