program main
  implicit none
  integer(8) :: n, i, largest_smaller_dividor
  read (*, *) n
  do i = 1, int(sqrt(dble(n))) + 1
    if (i ** 2 > n) exit
    if (mod(n, i) == 0) largest_smaller_dividor = i
  end do
  write (*, "(i0)") (largest_smaller_dividor - 1) + (n / largest_smaller_dividor - 1)
end program main
