n = gets.to_i m = 10**9 a = n / m b = n % m a -= 1 if a > b a = a.to_s.chars.map &:to_i def f(a, z) l = a.length return 1 if l == 0 ret = 0 d = a[0] d -= 1 unless z if a[0] > a[-1] b = a[1..-2].join.to_i if b > 0 ret += f((b-1).to_s.rjust(l-2, ?0).chars.map(&:to_i), true) end else ret += f(a[1..-2], true) end ret += d * f([9]*[(l-2),0].max, true) ret end ans = 0 ans += f(a, false) (1..a.length-1).each{|i| ans += f([9]*i, false)} p ans