#include <bits/stdc++.h>
#include <cstdint>
using namespace std;
 
 
long long N;
long long mindist = UINT64_MAX;
int main() {
  ios::sync_with_stdio(false);
  cin >> N;
  for(auto i = 1; i <= sqrt(N); ++i) {
    if((N % i) == 0 && (i + N/i -2) < mindist) {
      mindist = i + N/i -2;
    }
  }
  cout << mindist;
 
 
  return 0;