#include<iostream>
#include<vector>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define lim 101010
int dp[lim];
map<ll, int> ek;
ll e(ll k){
return k*(k+1)/2;
}
int main()
{
ll m = 0;
dp[0] = 0;
for(ll i = 1; i< lim; ++i){
ek[e(i)] = 1;
dp[i] = 1000;
for (ll j =0; e(j) <= i; j++) {
dp[i] = min(dp[i-e(j)] + 1, dp[i]);
}
// m = max(dp[i], m);
}
ll n;
cin >> n;
int res = 100;
for(ll i = 1; i< 1000; ++i){
for(ll j = 1; j< 1000; ++j){
ek[e(i) + e(j)] = 2;
}
if(n - e(i) - e(j) < lim){
res = min(res, dp[n-e(i)]+1);
}
}
for(ll i = 1; e(i) <= n; ++i){
if(e(i) == n){
cout << "1\n";
return 0;
}
if(ek[n - e(i)]){
res = min(res, ek[n-e(i)]+1);
}
if(n - e(i) < lim){
res = min(res, dp[n-e(i)]+1);
}
}
cout << res << endl;
}