#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, count = 0, tmp = 0;
  cin >> N;
  for (int i = 2; i < N; i++) {
    if (N % i == 0) {
      tmp = i + (N / i) - 2;
      if (count == 0 || count > tmp) {
        count = tmp;
      }
    }
  }
  cout << count;
  return 0;
}
