#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
int main() {
  ll N;
  cin >> N;
  ll a = 1, b = 1;
  stack<ll> s;
  for (ll i = 2; i <= 1000000; i++) {
    while (N % i == 0) {
      s.push(i);
      N /= i;
    }
  }
  if (N != 1) s.push(N);
  int size = s.size();
  while (size) {
    if (a <= b) {
      a *= s.top();
    } else {
      b *= s.top();
    }
    s.pop();
    size--;
  }
  cout << a + b - 2 << "\n";
}
