//  #牛客春招刷题训练营# https://www.nowcoder.com/discuss/726480854079250432
//  完全背包
//  思路是看题解才想到的,本来差点用成贪心了,但是发现不行,还没有反应过来是用完全背包
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <chrono>
#include <climits>
#include <cmath>
//#include <conio.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <thread>
#include <tuple>
#include <unordered_set>
#include <vector>
//#include <windows.h>
using namespace std;
//-----------------------------

int n, ans = 0;
int mmax;
int a[static_cast<int>(1e4 + 10)];

void solve() {
	memset(a, 127, sizeof(a));//---------记得初始化为一个很大的值
	cin >> n;
	mmax = sqrt(n) + 1;
	a[0] = 1;
	for (int i = 0; i <= mmax; i++) {
 		for (int j = 0; j <= n; j++) {//---------完全背包是正序的
			if (j < i * i) continue;//----------记得跳过不够的防止越界
			a[j] = min(a[j - i * i] + 1, a[j]);
		}
	}
	cout << a[n] - 1 << endl;
}

/*-----------C-O-D-E----------*/
int main()
{
	int T = 1;
	//IOS;// cin >> T;
	//read(T);
	//----------------


	//----------------

 	while (T--) {
		solve();
	}
	return 0;
 }
/*
				┏┓   ┏┓+ +
   ┏┛┻━━━┛┻┓ + +
   ┃       ┃  
   ┃   ━   ┃ ++ + + +
   ████━████ ┃+
   ┃       ┃ +
   ┃   ┻   ┃
   ┃       ┃ + +
   ┗━┓   ┏━┛
     ┃   ┃           
     ┃   ┃ + + + +
     ┃   ┃    Codes are far away from bugs with the animal protecting   
     ┃   ┃ +     神兽保佑,代码大概率无bug(不过神兽偶尔也会休息哦~)  
     ┃   ┃        Blessed by the mythical beast, may bugs stay far away
     ┃   ┃  +         
     ┃    ┗━━━┓ + +
     ┃        ┣┓
     ┃        ┏┛
     ┗┓┓┏━┳┓┏┛ + + + +
      ┃┫┫ ┃┫┫
      ┗┻┛ ┗┻┛+ + +++
*/