N = gets.to_i def f(x) return 0 if x < 10 v = 1 0.upto(Math.log10(x)) do |i| u = Rational(x, (10.pow(i))) % 10 v *= u.ceil end 1 + f(v) end puts f(N)