program problemC
  implicit none

  integer, parameter    :: i8 = selected_int_kind  ( 18 )
  integer ( kind = i8 ) :: N, i, memo, tmp

  read *, N

  memo = N

  do i = 1, N
     print *, i
     if ( real ( N ) / i == real ( N / i ) ) then
        tmp = N / i + i - 2
        if ( tmp < memo ) then
           memo = tmp
        end if
     end if
  end do

  print *, memo
  
end program problemC

     
