#include <iostream>
#include <limits>
using namespace std;

int main()
{
    long long n;
    long long ans = n;
    cin >> n;
    for(long long i = 1; i * i <= n; i++)
    {
        if(n % i == 0)
        {
            ans = min(ans, i + n/i - 2);
        }
    }
    cout << ans << endl;
    return 0;
}
