#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>

using namespace std;
typedef long long int ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
    ll n;  cin >> n;

    ll x,y;
  	ll max=0;

    for(ll i=9;i>0;i--){
        if(n%i==0){
            x=n/i;
            y=i;    //printf("%d,%d\n",x,y);
        }
      	if(max<x+y-2)[
          max=x+y-2;
          }
    }

    cout << max << endl;
}