Module Module1

    Sub Main()

        Dim N As Long = Console.ReadLine()
        Dim bunsi As Long = N
        Dim bunbo As Long = 1
        Dim finish As Boolean = False
        Dim yakuMin As Long = 2
        Dim yakuMax As Long = CInt(Math.Sqrt(N))
        Dim i As Long

        Do Until bunsi < bunbo OrElse finish
            finish = True
            For i = yakuMin To yakuMax
                If bunsi Mod i = 0 Then
                    bunbo *= i
                    bunsi \= i
                    yakuMin = i
                    finish = False
                    Exit For
                End If
            Next
        Loop

        Console.WriteLine(bunsi + bunbo - 2)
        ' Console.Read()

    End Sub

End Module
