#include <bits/stdc++.h>
int main(void) {
  long long int N;
  std::cin >> N;
  long long int min = N - 1;
  long long int prod = 1;
  for (long long int i = 2; i <= sqrt(N); i++) {
    while (N % i == 0) {
      N /= i;
      prod = prod * i;
      if (min > (prod - 1) + (N - 1)) {
        min = (prod - 1) + (N - 1);
      }
    }
  }
  std::cout << min;
  return 0;
}
