open System
open System.Collections.Generic

let read f = stdin.ReadLine() |> f
let factorize num =
    let acc = List<(int64)>()
    let mutable tmp = num
    for i in seq { 2L..int64(double num**0.5)+1L } do
        if tmp%i = 0L then
            let mutable cnt = 0L
            while tmp%i = 0L do
                cnt <- cnt + 1L
                tmp <- tmp / i
                acc.Add (i)
    if tmp <> 1L then
        acc.Add (tmp)
    if acc.Count = 0 then
        acc.Add (num)
    acc

let n = read int64
let ls = (factorize n).ToArray()
let mutable min = if ls.Length = 1 then ls.[0] else Int64.MaxValue
for i = 0 to ls.Length-2 do
    let x = ls.[0..i] |> Array.fold (fun acc elem -> acc * elem) 1L
    let y = ls.[i+1..ls.Length-1] |> Array.fold (fun acc elem -> acc * elem) 1L
    if (x+y-2L) < min then
        min <- (x+y-2L)
printfn "%d" min
