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