#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#define LL long long 
using namespace std;


int main()
{
    LL n,ans;
    scanf("%lld",&n);
    LL sq=sqrt(n)+0.5;
    for(LL i=sq;i>0;i--)
    {
        if(n%i==0)
        {
           ans=i+n/i-2;
           printf("%lld\n",ans);
           return 0;
        }
    }
    return 0;
}