(use srfi-11)
(define (solve n)
  (let loop ((t (x->integer (sqrt n))))
    (let-values (((q r) (quotient&remainder n t)))
      (if (zero? r)
          (+ t q -2)
          (loop (- t 1))))))

(print (solve (read)))
