program bank
implicit none
integer::a, n, i
read(5,*)a
n=0
do while(a>0)
if(a<6 .and. a>0) then
a=a-1
n=n+1
else if(a>=6 .and. a<9) then
a=a-6
n=n+1
else if(a>=9 .and. a<36) then
a=a-9
n=n+1
else if(a>=36 .and. a<81) then
a=a-36
n=n+1
else if(a>=81 .and. a<216) then
a=a-81
n=n+1
else if(a>=216 .and. a<729) then
a=a-216
n=n+1
else if(a>=729 .and. a<1296) then
a=a-729
n=n+1
else if(a>=1296 .and. a<6561) then
a=a-1296
n=n+1
else if(a>=6561 .and. a<7776) then
a=a-6561
n=n+1
else if(a>=7776 .and. a<46656) then
a=a-7776
n=n+1
else if(a>=46656 .and. a<59049) then
a=a-46656
n=n+1
else if(a>=59049) then
a=a-59049
n=n+1
end if
end do
if(a-a/2==0)
n=n
else
n=n-2
end if
write(6,*)n
end program bank