#include<iostream>
using namespace std;

int main()
{
	long long N;
	long long sum = 1000000000000;

	cin >> N;

	for(ll i = 1;i*i <= N; i++)
	{
		if (N % i != 0)continue;
		
			if ((i + N / i) <= sum)
			{
				sum = i+N/i;
			}	
		
	}

	

	cout << sum - 2 << endl;

	return 0;
}