program walk_on_multiplication_table
  implicit none
  integer(8) :: n, r
  read(*,*) n
  r = int(floor(sqrt(real(n,8)+0.5d0)),8)
  do while (mod(n,r) /= 0_8)
    r = r-1_8
  end do
  write(*,'(i0)') r+n/r-2_8
end program walk_on_multiplication_table