read n;
array=($(echo $n|factor|cut -d ' ' -f2-))
ans=10**15
len=${#array[@]}
if ((len==1));then
    echo $((${array[0]}-1))
    exit 0
elif ((len>=12));then
    echo $n|awk '   
                    {
                        n=$1
                        ans=1e12
                        for(i=1;i*i<=n;i++){
                            if(n%i!=0){
                                continue;
                            }
                            res = n/i+i-2;
                            if(res<ans){
                                ans=res;
                            }
                        }
                    }
                    END{print ans}
                '
    exit 0
fi

for ((b=1;b<(1<<len)-1;b++));do
    ga=1
    gb=1
    for ((i=0;i<len;i++));do
        if ((b & (1<<i)));then
            ((ga*=${array[i]}))
        else
            ((gb*=${array[i]}))
        fi
    done
    if ((ga+gb-2<ans));then
        ans=$(($ga+$gb-2))
    fi
done
echo $ans