#include <bits/stdc++.h>
using namespace std;
int prime(long long int n) {
  for (int i = 2; (long long int)i * i <= n; i++) {
    if (n % i == 0) return 0;
  }
  return 1;
}
int main() {
  long long int n;
  cin >> n;
  if (prime(n)) {
    cout << n - 1 << endl;
  } else {
    int a, b;
    int temp = sqrt(n);
    for (int i = temp; i >= 1; i--) {
      if (n % i == 0) {
        a = i;
        b = n / i;
        break;
      }
    }
    cout << a + b - 2 << endl;
  }
  return 0;
}
