#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
bool chmax(T& prov, const T& cur) {
  if (cur > prov) {
    prov = cur;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T& prov, const T& cur) {
  if (cur < prov) {
    prov = cur;
    return true;
  }
  return false;
}
ll gmin = LONG_MAX;
void df(ll x, ll y, const vector<ll>& n, int index) {
  if (index == n.size()) {
    chmin(gmin, x + y);
    return;
  }
  if (gmin <= x + y) {
    return;
  }
  df(x * n[index], y, n, index + 1);
  df(x, y * n[index], n, index + 1);
}
int main() {
  ll N;
  cin >> N;
  vector<ll> yaku;
  ll n = N;
  ll ans;
  ll sq = sqrt(N);
  for (ll i = 2; n > 1 && i <= sq; i++) {
    while (n % i == 0 && i != 1) {
      yaku.push_back(i);
      n /= i;
    }
  }
  if (yaku.size() == 0) {
    ans = N - 1;
  } else {
    df(1, 1, yaku, 0);
    ans = gmin - 2;
  }
  cout << ans << endl;
  return 0;
}
