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

#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define rng(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rbf(i, v) for (auto& (i) : (v))
#define All(x) (x).begin(),(x).end()
#define cAll(x) (x).cbegin(),(x).cend()
#define COL(x) cout << x << endl
#define CO(x) cout << x
#define int long long

template<typename T> inline constexpr auto square(T x) { return (x) * (x); }

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

const int MOD = 1000000007;
const int INF = INT_MAX;

signed main()
{
	int N;
	cin >> N;

	int n = N;
	int a = 1, b = 1;
	while (n % 2 == 0) {
		if (a < b) a *= 2;
		else b *= 2;

		n /= 2;
	}

	for (int i = 3; i <= N; i+=2) {
		while (n % i == 0) {
			if (a < b) a *= i;
			else b *= i;

			n /= i;
		}
	}

	COL(a+b-2);

	return 0;
}