program main implicit none integer*8::hole(0:9),n,x,y,i hole=[1,0,0,0,1,0,1,0,2,1] read*,n if(n==6)n=1 x=0 y=0 do while(n>0) x=x+hole(mod(n,10)) n=n/10 y=y+1 end do print*,min(2*(1+x)+y,2*y+(1+x)) end program