#include <algorithm>
#include <bits/stdc++.h>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#include <vector>
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define LONG_LONG_MAX 9223372036854775807LL
#define pblank putchar(' ')
#define ll LL
#define fastIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> P;
ll n, m, k;
const int maxn = 1e7 + 10;
template <class T>
inline T read()
{
    int f = 1;
    T ret = 0;
    char ch = getchar();
    while (!isdigit(ch))
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (isdigit(ch))
    {
        ret = (ret << 1) + (ret << 3) + ch - '0';
        ch = getchar();
    }
    ret *= f;
    return ret;
}
template <class T>
inline void write(T n)
{
    if (n < 0)
    {
        putchar('-');
        n = -n;
    }
    if (n >= 10)
    {
        write(n / 10);
    }
    putchar(n % 10 + '0');
}
template <class T>
inline void writeln(const T &n)
{
    write(n);
    puts("");
}
ll factor[maxn];
vector<ll> fac;
int tot;
const int S = 20; //随机算法判定次数，S越大，判错概率越小

LL mult_mod(LL a, LL b, LL c)
{
    a %= c;
    b %= c;
    LL ret = 0;
    while (b)
    {
        if (b & 1)
        {
            ret += a;
            ret %= c;
        }
        a <<= 1;
        if (a >= c)
            a %= c;
        b >>= 1;
    }
    return ret;
}

//计算  x^n %c
LL pow_mod(LL x, LL n, LL mod)
{ //x^n%c
    if (n == 1)
        return x % mod;
    x %= mod;
    LL tmp = x;
    LL ret = 1;
    while (n)
    {
        if (n & 1)
            ret = mult_mod(ret, tmp, mod);
        tmp = mult_mod(tmp, tmp, mod);
        n >>= 1;
    }
    return ret;
}

bool check(LL a, LL n, LL x, LL t)
{
    LL ret = pow_mod(a, x, n);
    LL last = ret;
    for (int i = 1; i <= t; i++)
    {
        ret = mult_mod(ret, ret, n);
        if (ret == 1 && last != 1 && last != n - 1)
            return true; //合数
        last = ret;
    }
    if (ret != 1)
        return true;
    return false;
}

bool Miller_Rabin(LL n)
{
    if (n < 2)
        return false;
    if (n == 2)
        return true;
    if ((n & 1) == 0)
        return false; //偶数
    LL x = n - 1;
    LL t = 0;
    while ((x & 1) == 0)
    {
        x >>= 1;
        t++;
    }
    for (int i = 0; i < S; i++)
    {
        LL a = rand() % (n - 1) + 1; //rand()需要stdlib.h头文件
        if (check(a, n, x, t))
            return false; //合数
    }
    return true;
}
LL gcd(LL a, LL b)
{
    if (a == 0)
        return 1;
    if (a < 0)
        return gcd(-a, b);
    while (b)
    {
        long long t = a % b;
        a = b;
        b = t;
    }
    return a;
}

long long Pollard_rho(LL x, LL c)
{
    LL i = 1, k = 2;
    LL x0 = rand() % x;
    LL y = x0;
    while (true)
    {
        i++;
        x0 = (mult_mod(x0, x0, x) + c) % x;
        LL d = gcd(y - x0, x);
        if (d != 1 && d != x)
            return d;
        if (y == x0)
            return x;
        if (i == k)
        {
            y = x0;
            k += k;
        }
    }
}
//对n进行素因子分解
void findfac(LL n)
{
    if (Miller_Rabin(n))
    { //素数
        factor[++tot] = n;
        return;
    }
    LL p = n;
    while (p >= n)
        p = Pollard_rho(p, rand() % (n - 1) + 1);
    findfac(p);
    findfac(n / p);
}
ll dp[maxn];
int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#endif
    n = read<ll>();
    ll up = (ll)sqrt(n * 1.0);
    ll res = n - 1;
    for (ll i = up; i >= 1; i--)
        if (n % i == 0)
        {
            res = i + n / i - 2;
            break;
        }
    writeln(res);
    return 0;
}

Measured memory_bytes: 2304