#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c;
  std::vector<int> vect;
  cin >> a;
  for (int i = 2; i < a; i++) {
    if (a % i == 0) {
      vect.push_back(i);
    }
  }
  b = (vect.size()) / 2;
  c = vect[b - 1] + vect[b] - 2;
  cout << c;
  return 0;
}
