#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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