# 17626번. Four Squares
importsysinput=sys.stdin.readlinen=int(input())ans=4# 최대값은 4
foriinrange(int(n**0.5),int((n//4)**0.5),-1):ifi**2==n:ans=1breakelse:tmp=n-i**2# i^2을 빼고 남은 수를 생각
forjinrange(int(tmp**0.5),int((tmp//3)**0.5),-1):ifi**2+j**2==n:ans=min(ans,2)continueelse:tmp=n-i**2-j**2forkinrange(int(tmp**0.5),int((tmp//2)**0.5),-1):ifn==i**2+j**2+k**2:ans=min(ans,3)print(ans)