https://www.acmicpc.net/problem/1699
# 시간초과
N = int(input())
M = int(N ** 0.5)
dp = [n for n in range(N+1)]
for i in range(2, M + 1):
for j in range(1, N + 1):
if j - i*i >= 0:
dp[j] = min(dp[j],dp[j-i*i] + 1)
print(dp[N])
# 업데이트 대상인 값만 처리하자
N = int(input())
M = int(N ** 0.5)
dp = [n for n in range(N+1)]
for i in range(2, M + 1):
for j in range(i*i, N + 1):
dp[j] = min(dp[j],dp[j-i*i] + 1)
print(dp[N])