#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, now, best_count, check;
  int i;
  bool first_check = false, change = false;
  cin >> N;
  for (i = N / 2; i > 1; i--) {
    if (N % i == 0) {
      if (first_check == false) {
        now = hypot((i - 1), ((N / i) - 1));
        best_count = N / 2;
        first_check = true;
      }
      check = hypot((i - 1), ((N / i) - 1));
      if (check < now) {
        now = check;
        best_count = i;
        change = false;
      }
    }
  }
  if (!change) cout << N - 1 << endl;
  return 0;
  cout << (best_count - 1) + ((N / best_count) - 1) << endl;
  return 0;
}
